question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

webpack dynamic import naming doesn't work

See original GitHub issue

I used comment to define chunkname as follows:

import(/* webpackChunkName: "chunk1" */'../components/chunk1.js')

then change webpack config output.chunkFilename: utils.assetsPath('js/[name].js')

but the build result has no file named chunk1.js.

At first I thought it’s a webpack bug. so I post an issue on webpack: https://github.com/webpack/webpack/issues/4861

But then I made a simple project without vuejs-template , chunkname works fine.

So I think there must be something wrong in the config of this template, could you help me find out ?

My test project: https://github.com/MarvinXu/webpack-chunkname-test

many thx!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

42reactions
6220119commented, Jun 9, 2017

In your .babelrc config file, make sure comment: true is used. In build/webpack.prod.conf.js file, make sure output.chunkFileName contains [name]. Example:

//...
output: {
    path: config.build.assetsRoot,
    filename: utils.assetsPath('js/[name].[chunkhash:5].js'),
    chunkFilename: utils.assetsPath('js/[name].[id].[chunkhash:5].js')
  },
//...
2reactions
LinusBorgcommented, Jan 26, 2018

In my opinion, There’s no need to add it to the docs because it’s the default value.

Back when this issue was relevant, we had comments: false in the Babel config, but that was months ago.

Adding something about this to the doc would be starting a list of “don’t do this” about general webpack features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dynamic import naming doesn't work · Issue #4861 - GitHub
In my TypeScript+Webpack case, { "module": "commonjs" } caused the problem. It worked fine on "es5" and "esnext".
Read more >
How to generate dynamic import chunk name in Webpack
You can use [request] placeholder to set dynamic chunk name. A basic example would be: const cat = "Cat"; import( /* webpackChunkName: "[ ......
Read more >
Fixing WebpackChunkName for Dynamic Imports - Time to Hack
Are the Webpack Magic Comments webpackChunkName not effective and working with Babel? See how to Fix it and Tips to avoid related problems....
Read more >
How Webpack Handles Dynamic Imports with Variable Paths
Whenever you import a file in your code, Webpack will look for it in the project directory and copy it to the build...
Read more >
How to name a webpack chunk (including split and common ...
In this post, we look at named outputs, including dynamic imports, split chunks, and common chunks. I recently wrote about code splitting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found