webpack: [ext] placeholder is not replaced when set in output.filename

Do you want to request a feature or report a bug?

Bug feature

What is the current behavior?

Using ‘[ext]’ placeholder in the output.filename doesn’t get replaced and instead you get a file with ‘filename.[ext]’.

If the current behavior is a bug, please provide the steps to reproduce.

Just setting the config to the following is enough:

output: {
    filename: '[name].[hash].[ext]'
}

What is the expected behavior?

‘[ext]’ should be replaced with the relevant extension.

Please mention other relevant information such as the browser version, Node.js version, webpack version, and Operating System.

Node Version: 8.9.4 Webpack Version: 4.1.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 36 (27 by maintainers)

Most upvoted comments

There is no such placeholder

截屏2021-06-28 下午11 09 37

Putting [ext] in Output related configuration items in the document can easily mislead developers. As of 2021-06, people are still misled by this document, which is enough to show that the document needs to be revised.

文档里面把 [ext] 放在 Output 相关配置项中,非常容易误导开发者。时至 2021-06 仍有人被这份文档误导,足以说明文档有需要修改的地方。

@sokra This placeholder exists in file-loader. Would it be a good idea to support it in webpack? This would allow the devs to do the following:

{
  entry: {
    main: "./main.js",
    styles: "./styles.css",
  },
  output: {
    filename: "[name].[contenthash].[ext]",
  }
}

It could be useful if webpack would handle other module types in the future.

Another use case could be:

{
  entry: {
    legacy: "./legacy.js",
    modern: "./modern.mjs",
    //                ^
  },
  output: {
    filename: "[name].[ext]",
  }
}

The bot probably shouldn’t close issues that are labelled.

Supporting [ext] would be awesome to avoid extra props like cssFilename: '[name].css' or the like in the future, but this may require a whitelist of valid output extensions for mapping common transpiler extensions to '.html', '.css', '.js' && '.wasm' based on their category, which is eventually inconvenient to maintain… ? On the other hand transpiler usage is slowly declining and there weren’t any new ones popping up for a while, so maybe it’s fine 😃

webpack.config.js

{
   entry: {
      'a': [ './a.ts', './a.tsx', './a.jsx', './a.coffee', ... ] // (?)
      'b': [ './b.scss', './b.less', './b.styl', ... ] // (?)
      'c': [ './c.pug', './c.hbs', './c.haml' ... ]  // (?)
      'd': './d.js',  ✅ 
      'e': './e.css', ✅ 
      'f': './f.html'  ✅
   },
   output: {
      filename: '[name].[contenthash].[ext]',
      chunkFilename: '[name].[contenthash].[ext]'
   }
}