-
Notifications
You must be signed in to change notification settings - Fork 158
Description
our dep optimization currently requires babel.
Part of this is inescapable today due to the need to handle @embroider/macros transforms.
However, in order to determine the minimal set of things to write for oxc (for use in rolldown, we must scan our entrypoints.
This immediately means that we need to traverse eagerly imported modules to find what our deps are and requires:
- gjs support -- via the
templateTag()plugin - hbs support (optionally, if you still have hbs) - -via the
hbsplugin - typescript support -- via
@babel/plugin-transform-typescript - decorator support -- via
decorator-transforms - we tell babel to use runtime helpers -- via
@babel/plugin-transform-runtime - re-add
babel-plugin-ember-template-compilationbecause libraries cannot compile templates to wire-format since ember-source is free to change the wireformat in minor versions (it's also not public API, and we do often want to change it)
So my disabling of all embroider-provided dep-optimization plugins started empty ([]), and I gradually added more of the plugins based on error-driven development to eventually end up at a booting up once again.
my vite plugins modificatinos
plugins: [
analyzer({
enabled: true,
fileName: 'bundle.html',
analyzerMode: 'static',
openAnalyzer: false,
defaultSizes: 'brotli',
}),
circleDependency(),
mkcert({
savePath: 'node_modules/.vite-plugin-mkcert/',
}),
icons({
autoInstall: true,
}),
ember(),
{
async config(config) {
console.log(config.optimizeDeps.rollupOptions.plugins);
config.optimizeDeps.rollupOptions.plugins = [
// hbs(),
templateTag(),
resolver(),
babel({
babelHelpers: 'runtime',
extensions,
configFile: false,
plugins: [
[
'@babel/plugin-transform-typescript',
{
allExtensions: true,
onlyRemoveTypeImports: true,
allowDeclareFields: true,
},
],
[
'babel-plugin-ember-template-compilation',
{
compilerPath: 'ember-source/dist/ember-template-compiler.js',
enableLegacyModules: [
'ember-cli-htmlbars',
'ember-cli-htmlbars-inline-precompile',
'htmlbars-inline-precompile',
],
transforms: [...macros.templateMacros],
},
],
[
'module:decorator-transforms',
{
runtime: {
import: import.meta.resolve('decorator-transforms/runtime-esm'),
},
},
],
[
'@babel/plugin-transform-runtime',
{
absoluteRuntime: import.meta.dirname,
useESModules: true,
regenerator: false,
},
],
...macros.babelMacros,
],
}),
];
},
},
babel({
babelHelpers: 'runtime',
extensions,
}),
],Unfortunately, for my app, NullVoxPopuli/limber#1968, this means that I've re-added all the babel plugins I was already using.
but my app here is very minimal, and this is likely the minimal set of transforms we need to run on an app's libraries during the depOptimization phase.
So, this is six transforms that may need to be re-implemented in oxc / as rollup plugins:
- macros
- gjs
- hbs
- typescript
- decorator-transforms
we won't need this when we move to spec-decorators - babel-plugin-ember-template-compilation
Once this is done, we can skip the whole extra parse + write from babel, and just rely on the ESTree that Rollup's transform hook provides: https://rollupjs.org/plugin-development/#transform
In the big 3 million line codebase I have at work, babel takes up about half of the build time:
Rolldown is 10-30x faster than rollup.
OXC is 40x faster than babel.
And I don't know what eliminating babel and using rollup's ASTs would be like.
I also don't know if using rollup's ASTs means we get to use OXC in rolldown.
Does rolldown still consume JS-written plugins? idk
(paired with @mansona on the creation of this list)