serverless-bundle
serverless-bundle copied to clipboard
minified build
Hi, I was comparing the result of the serverless-bundle
(I'm using the beta branch because I'm using typescript to develop) with serverless-plugin-ncc
and I see that the final bundle of serverless-bundle is quite havier compared to serverless-plugin-ncc
index.js
from serverless-bundle
is 2,319KB
index.js
from serverless-plugin-ncc
is 1,105KB
I don't know internally if there are differences but as far as I can see it's not possible to minify the serverless-bundle output.
So I've two questions:
- would it be possible to add that option to serverless-bundle?
- have you ever thought to create an ncc plugin? (because I know guys that you are damn amazing in support serverless and I would like to see something from your own!).
serverless-plugin-ncc
seems to not supportserverless-offline
and many cool things that come from your bundle plugin.
When I had first worked on serverless-bundle, I had worked on minimizing. But it seemed to slow down the build times by a lot. If you are interested in taking this on, I would start by using https://www.npmjs.com/package/webpack-bundle-analyzer to compare the two outputs.
For question 2, I'm not totally sure what you mean. What do you think serverless-bundle is doing different from serverless-plugin-ncc?
Maybe we can use a version without mangling and compression:
{ minimize: true, minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: ENABLE_SOURCE_MAPS,
terserOptions: {
mangle: false,
compress: false,
}
})
] },
this results in the comments being removed which already helps alot!
Hi, any updates on this? We would like to use minified build files.
Also wondering, maybe not on topic here, but it seems like all optimizations are turned off. Our files are really big after compiling and includes all imported code. Does tree shaking not work in the current webpack setup?
V5 Beta has minification enabled 🙂
@thomaschaaf Thanks! Seems to work 😄
So glad I just found this issue, Just got to a point where I realised my serverless functions were including code that I had not imported from a shared lib which obviously meant tree shaking wasn't working.
This seems to be solved in the latest v5 beta. Nice work.
In case you don't want to move to V5 Beta yet, use serverless-plugin-optimize
which in my case actually outputs a smaller bundle
Is there a way to disable minimization? I'm using serverless-mysql in my code and get the following error:
Received packet in the wrong sequence
It seems like this is an issue with webpack minimization because rolling back to 4.4.0 fixes the issue
Related issue: https://github.com/mysqljs/mysql/issues/1655
Is there a way to disable minimization? I'm using serverless-mysql in my code and get the following error:
Received packet in the wrong sequence
It seems like this is an issue with webpack minimization because rolling back to 4.4.0 fixes the issue
this could be mitigated using the esbuild instead of babel, e.g. with the following config (keepNames set to true is the key point here):
bundle:
caching: true
esbuild: true
minifyOptions:
keepNames: true
Can confirm this fixed the problem with packets in the wrong sequence. Cheers @sromic!
bundle:
minifyOptions:
keepNames: true