packer::bundle() parameter for esbuild bundle
Hey man,
I found out about packer a couple of months ago and have been loving it, seriously! But I noticed build times can be quite slow, mostly because of babel, so I wanted to suggest using esbuild-loader for bundling/minifying via esbuild while still using packer::bundle() (so this could be the default bundling or just a parameter on packer::scaffold_golem()).
The modifications needed are very well explained at esbuild-loader's README.md, all it should take is:
- Installing
esbuildduringpacker's scaffold - Creating
webpack.common.jswithesbuild-loaderimports and specific modifications to theoptionsobject - Creating
loaders.jsonwith theesbuild-loaderconfigs instead ofbabel-loader
So webpack.common.js would look something like:
const {
ESBuildPlugin,
ESBuildMinifyPlugin
} = require('esbuild-loader')
...
var options = {
entry: entryPoints,
output: {
filename: '[name].js',
path: path.resolve(__dirname, JSON.parse(outputPath)),
},
externals: externals,
module: {
rules: loaders
},
plugins: [
new ESBuildPlugin()
],
optimization: {
minimize: true,
minimizer: [ new ESBuildMinifyPlugin({
target: 'es2015'
}) ]
}
};
...
And loaders.json should look like:
[
{
"test": "\\.js$",
"loader": "esbuild-loader",
"options": {
"target": "es2015",
"loader": "jsx"
}
},
...
]
This setup has been working wonderfully for me, I got the build time to go down from ~3.3min to ~12sec, so I'd love to see it implemented on packer!
Apologies, I totally forgot about this issue!
Thanks for sharing this, I just tried on a large project, and it's indeed mighty fast! I'll will try to add a add_plugin_esbuild.