将 webpack 升级到版本 5.64.0 时,module.rule.generator.publicPath
已停止正常工作。
module.exports={
// ....,
generator: {
filename: devMode
? "../fonts/[name][ext][query]"
: "fonts/[name][hash][ext][query]",
publicPath: "fonts",
},
}
我有这个错误:
ERROR in ./src/frontlib.sass
Module build failed (from ./node_modules/mini-css-extract-plugi/dist/loader.js):
HookWebpackError: Invalid URL at tryRunOrWebpackError
现在,即使我将 Webpack 降级到以前的版本,我仍然遇到相同的错误。
如何将生成器 publicPath
设置到新的 Webpack 版本中?
最佳答案
我也遇到了同样的问题,但是我成功了。 生成器不支持 publicPath。您必须使用编译器的输出。
...
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]'
}
}
我在此存储库中有一个示例: https://github.com/Vanillabacke/webpack-5-settings
关于带有 publicPath 的 Webpack Assets 生成器无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69966803/