The result is improved bundle size and performance, while supporting the same browsers.
+1 for this
https://github.com/babel/preset-modules
we are testing this right now, seems stable and could be a replacement for babel-env for modern build!
currently we added it for modern build like this:
if (envName === 'modern') {
return [
'@babel/preset-modules',
{
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-transform-runtime', { helpers: true }]
]
}
];
}
@simllll what bundle size saving?
@academici it reduced the overall size from 414 to 390 KB (gzipped).
Especially the commons bundle which includes the vue runtime, router, etc. got smaller (from 63 to 47KB)
Thanks for the feature request. 馃樃
I think @j1gs4w solution is a proper way if you want to use @babel/preset-modules
.
I'm considering if we should bring into Nuxt as default preset, some issues I can think is:
babel 7.8.0
, some ECMA 2020 features (optional-chaining
, nullish-coalescing-operator
) have been introduced into @babel/preset-env
, but @babel/preset-modules
does't support the new syntax transforming.@babel/preset-modules
is outside babel core repo, so it may not sync the api and features with latest babel timely.Maybe we could extract @j1gs4w solution into a Nuxt module.
Note that if you use JSX syntax, you may want to add the @vue/babel-preset-jsx
preset:
if (envName === 'modern') {
return [
[
'@babel/preset-modules',
{
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-transform-runtime', { helpers: true }],
],
},
],
['@vue/babel-preset-jsx', {}],
]
}
Unless I as misunderstanding it looks like its now possible to get the same benefits whilst continuing to use preset-env? https://babeljs.io/blog/2020/03/16/7.9.0 We just need to expose the new bugfixes option
@dansullivan86 PR: https://github.com/nuxt/nuxt.js/pull/7144
You can set this option after it gets shipped:
export default {
build: {
babel: {
presets: ['@nuxt/babel-preset-app', { bugfixes: true }]
}
}
Most helpful comment
@dansullivan86 PR: https://github.com/nuxt/nuxt.js/pull/7144
You can set this option after it gets shipped: