Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modules from web_modules if present #4

Merged
merged 1 commit into from
Apr 23, 2020

Conversation

israelroldan
Copy link
Contributor

Hey @yyx990803 thank you for putting this together, it will be super useful moving forward!
I was inspired by the idea to integrate support for snowpack and gave an initial integration a try.

This assumes you have run npx snowpack in the directory you're working on, so I'm not calling it an integration quite yet.

However, this supports having modules present in web_modules and serving them as named packages directly from there. Quick example:

index.html:

<div id="app"></div>
<script type="module">
import { createApp } from 'vue'
import Comp from './Comp.vue'

createApp(Comp).mount('#app')
</script>

Comp.vue:

<template>
  <div>
    Today's date is: {{ dayjs().format('dddd MMMM D, YYYY') }}
  </div>
</template>

<script>
import dayjs from 'dayjs';
export default {
  methods: {
    dayjs
  }
}
</script>

Then run:

$ npm init -y
$ npm i --save dayjs
$ npx snowpack
$ npx vite

I'm curious to hear what you think about this.

Copy link
Member

@yyx990803 yyx990803 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best not to do sync fs access in the rewrite function since it gets called on every js file served.

The module resolution should be placed here

I think Snowpack also generates a import map json file - which should be used.

@israelroldan
Copy link
Contributor Author

Oops, I clicked the Request re-review button a bit too early, I have another commit in the works :)

@israelroldan israelroldan marked this pull request as draft April 22, 2020 17:42
@israelroldan israelroldan marked this pull request as ready for review April 22, 2020 18:30
src/server/plugins/modules.ts Outdated Show resolved Hide resolved
@FredKSchott
Copy link
Contributor

Just wanted to say that this looks great! Happy to help answer any Snowpack questions that come up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants