Vue-cli: tree-shaking not work

Created on 7 May 2019  路  1Comment  路  Source: vuejs/vue-cli

Version

3.7.0

Reproduction link

demo: https://github.com/PanJiaChen/tree-shaking-test

Step

npm install

npm run build

You can view the generated js file in the /dist folder. Found that tree-shaking did not work.

I only import the banana function in About.vue, but orange was also packaged.

Step2

Now find router.js, comment About2

{
  path: '/about2',
  name: 'about2',
  component: () => import('./views/About2.vue'),
}

Execute `npm run build again

Found that tree-shaking has taken effect again.

Conclusion

Found that when a file is referenced by multiple pages, tree-shaking will not work. But at the same time you can find that the tree-shaking of foo and bar in fruit.js has been in effect.

>All comments

https://github.com/webpack/webpack/issues/7500

This is the _expected_ behavior. Tree shaking is not supported on async chunks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b-zee picture b-zee  路  3Comments

wahidrahim picture wahidrahim  路  3Comments

BusyHe picture BusyHe  路  3Comments

csakis picture csakis  路  3Comments

chasegiunta picture chasegiunta  路  3Comments