Do you want to request a feature or report a bug?
Bug (?)
What is the current behavior?
When defining options.runtimeChunk
with true
or another value, my entry modules are being written with the chunkFilename
option instead of the filename
option. However, the runtime doesn’t seem to load my entry modules. When I add a script tag for the entry file, the page loads normally.
Which modules do I need to write script tags for? I’m automatically injecting all files that are in the directory controlled by the filename
property.
If the current behavior is a bug, please provide the steps to reproduce.
const config = {
entry: {
app: [
path.join(myCwd, 'app/main/index.js'),
path.join(myCwd, 'app/main/hmr.js'),
],
},
mode: isDist ? 'production' : 'development',
optimization: {
namedModules: true,
noEmitOnErrors: !isDist,
runtimeChunk: true,
splitChunks: false,
},
output: {
path: destPath,
filename: 'entry/[name]/index.js',
chunkFilename: 'chunks/[name]/index.[chunkhash].js',
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
],
resolve: {
modules: [
'node_modules',
path.resolve(myCwd, 'app'),
],
},
}
What is the expected behavior?
Entry chunks are emitted using the filename property.
Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.
- webpack v4.0.1
- node v8.9
@nirazul I’m also running into this, with a similar config to yours.
If I omit the
output.chunkFilename
option, entry chunks properly usefilename
.However I then can’t customize
chunkFilename
.@sokra I think this is a bug, using
output.chunkFilename
shouldn’t changeoutput.filename
.Another thing I noticed, including
runtimeChunk: 'single'
also breaksoutput.filename
Take a look at these outputs:
I’ve also experienced the issues described by @davidmerrique, and there is another related issue:
I’m getting this error:
There’s no option in
optimization.runtimeChunk
to set the file name, so it’s usingoutput.filename
, which includes[chunkhash]
. The only way to avoid this is to remove the[chunkhash]
fromoutput.filename
, which I don’t want to do.@sokra These issues seem to be quite serious – will you be able to look into them soon?
I’ve made a small plugin which allows you to rename chunks, or use your
output.filename
option for initial chunks with entry and without runtime. Should help with this issue: npm link.@MhMadHamster
I’ve tried out your plugin and it works like a charm! Thank you very much!
Would be nice to introduce the functionality into wepback core as the documentation states that by default, entry chunks should use the filename template.
@flibustier7seas Ya, I was doing something like:
filename: (isDev ? "[name].js" : "[name]-[chunkhash].js")
.Edit: Now using
filename: (isHot ? "[name].js" : "[name]-[contenthash:8].js")
.As we needed this for Next.js I spent some time writing a plugin that applies the fix @SevInf wrote:
So, will this be fixed in webpack 4.x?