nonzzz / vite-plugin-compression

vite plugin. compress your bundle file.
MIT License
171 stars 10 forks source link

`deleteOriginalAssets` option removes `manualChunks` #35

Closed ntltd closed 1 year ago

ntltd commented 1 year ago

Bug report 🐞

With this build config, the plugin seems to remove chunking strategy when using deleteOriginalAssets option:

plugins: [
      react({
        fastRefresh: process.env.NODE_ENV !== 'test'
      }),
      compression({ deleteOriginalAssets: true })
    ],
build: {
      rollupOptions: {
        output: {
          manualChunks: function manualChunks(id) {
            if (id.includes('node_modules')) {
              if (id.includes('lodash')) {
                return 'lodash'
              }
              if (id.includes('moment')) {
                return 'moment'
              }
              if (id.includes('leaflet')) {
                return 'leaflet'
              }
              if (id.includes('datadog')) {
                return 'datadog'
              }
              return 'vendor'
            }
            if (id.includes('components/icons')) {
              return 'icons'
            }
            if (id.includes('helpers/translations')) {
              return 'translations'
            }
          }
        }
      }
    }

Do you have an idea why? Thanks

Version & Environment

"@vitejs/plugin-react": "^4.0.2",
"vite": "^4.4.0",
"vite-plugin-compression2": "^0.10.2",

Expectation

Manual chunks should be generated:

image

Actual results (or Errors)

Manual chunks are not generated anymore:

image
nonzzz commented 1 year ago

umm. Because you don't set threshold so the plugin will consume all chunk

nonzzz commented 1 year ago

as i can know. manualChunks also be consume in the full process. Have you generated the corresponding gz file locally?

ntltd commented 1 year ago

Not sure if threshold has to be set because I don't want to filter files by size. If I disable deleteOriginalAssets, gz files of my chunks are generated. When I enable the option, they are delete at build.

nonzzz commented 1 year ago

I mean you turned deleteOriginalAssets on to generate lodash.js.gz?

ntltd commented 1 year ago

If I use the compress() plugin with deleteOriginalAssets turned off, it generates lodash.js.gz along lodash.js file:

image

But if I turn on the option, the files are not generated anymore, the chunk seems to not be taken in account anymore.

nonzzz commented 1 year ago

jesus, i set the same option in my local but it can work well. I'm not sure what happened in your local :( . I think if you can provide a minimum repo is well.

nonzzz commented 1 year ago

By the way. the logo info is unreliable. When the chunk has side effect. It won't print out in your terminal. You should view the generated

ntltd commented 1 year ago

Yep, I tried to create a new repository with the same config, but it seems to work indeed: https://github.com/ntltd/vite-plugin-compression I'm trying to figure out what's happening on the other repository 🤔

ntltd commented 1 year ago

Ok got it! It's not the same order on the prompt when I use the deleteOriginalAssets option but compressed files are here 🙈 Really sorry for disturbing and thanks for your amazing work!