serverless-bundle icon indicating copy to clipboard operation
serverless-bundle copied to clipboard

minified build

Open StErMi opened this issue 4 years ago • 11 comments

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:

  1. would it be possible to add that option to serverless-bundle?
  2. 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 support serverless-offline and many cool things that come from your bundle plugin.

StErMi avatar May 30 '20 13:05 StErMi

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?

jayair avatar May 30 '20 18:05 jayair

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!

thomaschaaf avatar Feb 04 '21 12:02 thomaschaaf

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?

remcoabalain avatar Jun 16 '21 07:06 remcoabalain

V5 Beta has minification enabled 🙂

thomaschaaf avatar Jun 16 '21 09:06 thomaschaaf

@thomaschaaf Thanks! Seems to work 😄

remcoabalain avatar Jun 16 '21 09:06 remcoabalain

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.

chris-hinds avatar Jul 14 '21 09:07 chris-hinds

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

marianocodes avatar Aug 20 '21 22:08 marianocodes

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

rogueturnip avatar Sep 18 '21 15:09 rogueturnip

Related issue: https://github.com/mysqljs/mysql/issues/1655

spidgorny avatar Dec 25 '21 19:12 spidgorny

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

sromic avatar Dec 29 '22 11:12 sromic

Can confirm this fixed the problem with packets in the wrong sequence. Cheers @sromic!

bundle:
  minifyOptions:
    keepNames: true

beniusij avatar Feb 27 '23 15:02 beniusij