webpack adding imports from lazy loaded entry to main entry

203 views Asked by At

I'm using webpack (v3.5.6) for building (bundling and compiling) a web application. In our main entry we (try to) lazy load another entry file, using this syntax:

import(/* webpackChunkName: 'charts' */ './charts').then((module) => { /* do something with module */});

With these entries defined:

entry: {
    'charts' : [`src/charts.ts`],
    'main' : [`src/main.ts`]
},

When webpack does its thing, it generates both entries but the main entry also contains the charts entry (plus all its imports).

In the webpack config, I have defined:

new webpack.optimize.CommonsChunkPlugin({
    names: ['charts'],
    minChunks: Infinity,
    async: true
})

Anyone got an idea why the main.js output also contains the charts bundle?

1

There are 1 answers

0
schmkr On BEST ANSWER

Turns out, this was not caused by webpack but by the way our Typescript config had set module to commonjs instead of es2015 or amd.