para
para

Reputation: 51

Webpack asset generator with publicPath not working?

when upgrading webpack to version 5.64.0, module.rule.generator.publicPath has stopped working properly.

module.exports={
  // ....,
  generator: {
    filename: devMode
      ? "../fonts/[name][ext][query]"
      : "fonts/[name][hash][ext][query]",
    publicPath: "fonts",
  },
}

and I have this error:

ERROR in ./src/frontlib.sass
Module build failed (from ./node_modules/mini-css-extract-plugi/dist/loader.js):
HookWebpackError: Invalid URL at tryRunOrWebpackError 

Now I still have the same error even if I downgrade Webpack to the previous version.

How to set generator publicPath into the new Webpack version?

Upvotes: 2

Views: 1459

Answers (1)

Vanillabacke
Vanillabacke

Reputation: 41

I had the same problem, but i got it to work. The generator does not support publicPath. You have to use the output of the compiler.

...

entry: {
    main: './src/inputFile.js'
},
output: {
    filename: 'outputName.js',
    path: path.resolve(__dirname, '../outputFolder')
}

...

{
    test: /.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
    type: "asset/resource",
    generator: {
        filename: './fonts/[hash][ext]'
    }
}

I have an example in this repo: https://github.com/Vanillabacke/webpack-5-settings

Upvotes: 4

Related Questions