output.publicPathcss
将publicPath在浏览器中引用时指定输出文件的公共URL地址。webpack
处理静态资源引用地址用的 。web
打包后默认状况是url(文件名) 这样必须确保资源文件和css处于同一目录,但咱们显然不但愿这样,但愿修改打包引用地址。浏览器
{test: /\.(?:jpg|png|gif)$/, use: [{ loader: 'file-loader?name=img/[name].[hash:6].[ext]' //打包后在img目录下 }}
上述文件通过webpack打包后,在打包文件中以下:ui
/***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__.p + "img/banner.d24625.png"; /***/ }),
可是个人设计是打包后的图片是放在public下的img,此时图片天然找不到(若是不加publicpath则为img/xxx),因此须要设置publicpath改变图片路径url
解决方案:设计
output: { path: path.resolve("./web/public"),//打包后的文件存放的地方,上面提到的图片此时在web/public/img目录下 filename: "bundle.js",//打包后输出文件的文件名, publicPath: 'public/' //引用图片路径变为web/public/img }