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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
26 changes: 0 additions & 26 deletions create-snowpack-app/app-template-11ty/_output/static/index.css

This file was deleted.

This file was deleted.

16 changes: 13 additions & 3 deletions plugins/plugin-vue/README.md
Expand Up @@ -9,10 +9,20 @@ npm install --save-dev @snowpack/plugin-vue
```js
// snowpack.config.mjs
export default {
plugins: ['@snowpack/plugin-vue'],
plugins: [
'@snowpack/plugin-vue',
{
/* see optional “Plugin Options” below */
},
],
};
```

#### Plugin Options
## Plugin Options

(none)
You may customize Vue's bundler behavior using the following plugin options.

| Name | Type | Description |
| :------------- | :-------: | :--------------------------------------------------------------------------------------------------- |
| `optionsApi` | `boolean` | Enable/disable [Options API](https://v3.vuejs.org/api/options-api.html) support. Defaults to `true`. |
| `prodDevtools` | `boolean` | Enable/disable devtools support in production. Defaults to `false`. |
1 change: 1 addition & 0 deletions plugins/plugin-vue/package.json
Expand Up @@ -13,6 +13,7 @@
"access": "public"
},
"dependencies": {
"@rollup/plugin-replace": "^2.4.2",
"@vue/compiler-sfc": "^3.0.10",
"hash-sum": "^2.0.0"
},
Expand Down
19 changes: 18 additions & 1 deletion plugins/plugin-vue/plugin.js
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const hashsum = require('hash-sum');
const compiler = require('@vue/compiler-sfc');
const scriptCompilers = require('./src/script-compilers');
const replace = require('@rollup/plugin-replace');

const inlineSourcemap = (code, map) =>
code +
Expand Down Expand Up @@ -37,7 +38,23 @@ function displayError({contents, filePath, error}) {
return output.join('\n');
}

module.exports = function plugin(snowpackConfig) {
module.exports = function plugin(snowpackConfig, pluginOptions = {}) {
// Enable proper tree-shaking for Vue's ESM bundler
// See http://link.vuejs.org/feature-flags
const packageOptions = snowpackConfig.packageOptions || snowpackConfig.installOptions;
if (packageOptions.source === 'local') {
packageOptions.rollup = packageOptions.rollup || {};
packageOptions.rollup.plugins = packageOptions.rollup.plugins || [];
const { optionsApi = true, prodDevtools = false } = pluginOptions;
packageOptions.rollup.plugins.push(
replace({
values: {
'__VUE_OPTIONS_API__': JSON.stringify(optionsApi),
'__VUE_PROD_DEVTOOLS__': JSON.stringify(prodDevtools),
}
}),
);
}
return {
name: '@snowpack/plugin-vue',
resolve: {
Expand Down