在使用webpack的mini-css-extract-plugin插件时,打包css后样式表里引用文件的路径都有问题,按照网上的教程,大部分都是说修改publicPath
就结论来说,确实只需要将publicPath改为: "../"即可

但是,需要注意的是,当file-loader或者url-loader配置了publicPath时
,mini-css-extract-plugin.loader中的publicPath将不再生效

所以最终应该这样配置
{ test: /\.less$/, use: [ { loader: MiniCssExtractPlugin.loader, options: {
esModule: false, publicPath: "../", hmr: devMode } }, "css-loader", { loader:
"postcss-loader", options: { ident: "postcss", plugins: [ require(
"postcss-preset-env")() ] } }, "less-loader", ] }, { test:
/\.(jpg|bmp|png|jpeg|gif|tiff)$/, loader: "url-loader", options: { limit: 64 *
1024, outputPath: "img", name: devMode ? "[name].[ext]" :
"[name].[hash:6].[ext]", esModule: false, }, { test:
/.(woff|woff2|eot|ttf|otf|TTF|svg).*?$/, loader: "file-loader", options: { name:
devMode? "[name].[ext]" : "[name].[hash:6].[ext]", outputPath: "font", } }

技术
友情链接
码工具
Toolsou
API参考文档
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信