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

Enable proper tree-shaking of Vue's ESM bundler #3382

Merged
merged 4 commits into from May 27, 2021
Merged

Conversation

natemoo-re
Copy link
Contributor

Changes

Updates @snowpack/plugin-vue to automatically replace Vue's Feature Flags with boolean literals. This improves the treeshaking of Vue's ESM bundler (and removes a very persistent console.warn).

Testing

yarn link locally and run in Astro. The warning is gone!

Docs

Yes the docs were updated!

@natemoo-re natemoo-re requested a review from a team as a code owner May 27, 2021 17:41
@vercel
Copy link

vercel bot commented May 27, 2021

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/7zMtK3KicWkdMy4kRiU7tQMvWHt9
✅ Preview: https://snowpack-git-fix-vue-treeshake-pikapkg.vercel.app

// Enable proper tree-shaking for Vue's ESM bundler
// See http://link.vuejs.org/feature-flags
const packageOptions = snowpackConfig.packageOptions || snowpackConfig.installOptions;
if (packageOptions && packageOptions.source === 'local') {
Copy link
Collaborator

@drwpow drwpow May 27, 2021

Choose a reason for hiding this comment

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

@natemoo-re made a small change:

- if (packageOptions.source === 'local') {
+ if (packageOptions && packageOptions.source === 'local') {

The plugin-vue test which doesn’t fully load Snowpack was throwing because the default wasn’t set. While that’s probably more the test’s concern than the plugin, I still think it’s easier to keep plugin tests writing not loading the entire Snowpack runtime, and also not mocking Snowpack’s normalization, either (which may change). Hence the change here in the plugin rather than the test.

I wasn’t really sure what gets normalized IRT the Snowpack config, so I just played it safe here. But if you‘d prefer throwing an error if packageOptions doesn’t exist instead, I could do that, too.

@drwpow drwpow merged commit 1241098 into main May 27, 2021
@drwpow drwpow deleted the fix/vue-treeshake branch May 27, 2021 20:50
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.

None yet

3 participants