webpack.js.org icon indicating copy to clipboard operation
webpack.js.org copied to clipboard

`resolve.alias`: document replacement for deprecated `null-loader` regexp matching

Open juliangilbey opened this issue 1 year ago • 1 comments

The docs say that null-loader is deprecated and gives an example of how to do it: https://github.com/webpack/webpack.js.org/blob/355360020cad11e51dba5f2f51fe8e6823e82e8e/src/content/configuration/resolve.mdx#L124 https://github.com/webpack/webpack.js.org/blob/355360020cad11e51dba5f2f51fe8e6823e82e8e/src/content/configuration/resolve.mdx#L144-L154

But null-loader can also use regexps to drop files, like this:

module.exports = {
  //...
  module: {
    rules: [
      {
        test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
        use: 'null-loader'
      },
    ]
  },
};

It would be helpful if the resolve.alias documentation could give an example of how to handle such a case. I think that the following would be the appropriate replacement, but I am far from certain that the resolver treats the alias as a regexp:

module.exports = {
  //...
  resolve: {
    alias: {
      '\\.woff2(\\?v=\\d+\\.\\d+\\.\\d+)?$': false,
    },
  },
};

juliangilbey avatar Jul 17 '23 10:07 juliangilbey

resolve.alias doesn't accept RegExp paths

snitin315 avatar Mar 22 '24 16:03 snitin315