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

Fix importing from Svelte files #764

Merged
merged 3 commits into from
Aug 7, 2020
Merged

Fix importing from Svelte files #764

merged 3 commits into from
Aug 7, 2020

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Aug 7, 2020

Changes

Fixes #745, where import statements weren’t detected within Svelte files. The issue was that build was just fine (this PR adds a new test anyway, even though it was actually passing already without the fix), but this was an issue in the dev server. It turned out it was an issue with the installer, where it wouldn’t auto-detect imports.

We were scanning all <script type="module"> tags (HTML), but not <script> tags (Svelte, Vue). This PR changes that.

Screenshots

Screen Shot 2020-08-07 at 2 33 24 PM

Testing

In the new test/build/svelte-import test, run yarn snowpack dev and ensure the dev server loads.

@drwpow drwpow requested a review from a team as a code owner August 7, 2020 19:56
@vercel
Copy link

vercel bot commented Aug 7, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/e8lzotxuk
✅ Preview: https://snowpack-git-drwpow-svelte-import.pikapkg.vercel.app

@@ -30,6 +30,8 @@ const LOCKFILE_HASH_FILE = '.hash';
export const HAS_CDN_HASH_REGEX = /\-[a-zA-Z0-9]{16,}/;
// NOTE(fks): Must match empty script elements to work properly.
export const HTML_JS_REGEX = /(<script.*?type="?module"?.*?>)(.*?)<\/script>/gms;
export const SVELTE_VUE_REGEX = /(<script[^>]+)(.*?)<\/script>/gms;
Copy link
Collaborator Author

@drwpow drwpow Aug 7, 2020

Choose a reason for hiding this comment

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

I’m thinking it’s safer to keep existing behavior for HTML—only allow <script type="module">—but make an exception for Vue & Svelte where all <script> tags are parsed as JS. Is this correct?

@@ -54,13 +54,14 @@ describe('snowpack build', () => {
`File not found in snapshot: ${entry.path2.replace(actual, '')}/${entry.name2}`,
);

// don’t compare web_modules contents for Windows
if (process.platform === 'win32' && entry.path1.includes('web_modules')) continue;
Copy link
Collaborator Author

@drwpow drwpow Aug 7, 2020

Choose a reason for hiding this comment

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

This commit was brought to you by

- const file = "src/App.svelte";
+ const file = "src\\App.svelte";

@drwpow drwpow merged commit 810cac1 into master Aug 7, 2020
@drwpow drwpow deleted the drwpow/svelte-import branch August 7, 2020 21:43
@PlkMarudny
Copy link

PlkMarudny commented Sep 20, 2020

It still does not work in the 2.11.1, I am referring to #752 for reproducing steps, the error is, however:

[snowpack] Import "svelte" could not be resolved. If this is a new package, re-run Snowpack with the --reload flag to rebuild. If Snowpack is having trouble detecting the import, add "install": ["svelte"] to your Snowpack config file.

@FredKSchott
Copy link
Owner

Sorry, I can't reproduce. Did you try running with snowpack dev --reload?

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.

Module imports from svelte files not included in web modules in dev mode.
3 participants