webpack 发表于 2018-05-25 打包字体图标和图片的方式(参考:https://github.com/webpack-contrib/file-loader)使用之前要安装url-loader、file-loader 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657{ test: /\.(woff|woff2|ttf|eot|svg)(\?]?.*)?$/, use: [ { loader: "file-loader", options: { name: "assets/fonts/[name]-[hash].[ext]", publicPath: './' } } ]},/** 这种打包字体的方式会直接以hash的方式重命名* */{ test: /\.(woff|woff2|ttf|eot|svg)(\?]?.*)?$/, loader: 'file-loader?publicPath=./&outputPath=assets/fonts/'},/** 下面的方式可用* */{ test: /\.(woff|woff2|ttf|eot|svg)(\?]?.*)?$/, loader: 'file-loader', options: { name: "assets/fonts/[name]-[hash].[ext]", publicPath: './' }},/**也可以把file-loader改成url-loader转成base64编码,但是会扩大内存***/{ test: /\.(woff|woff2|ttf|eot|svg)(\?]?.*)?$/, use: [ { loader: "url-loader", //如果用file-loader会查询不到资源 options: { name: "assets/fonts/[name]-[hash].[ext]" } }, ]},{ test: /\.(jpg|jepg|png|gif)(\?]?.*)?$/, use: [ { loader: "file-loader", options: { name: "assets/imgs/[name]-[hash].[ext]" } } ]} 本文作者: 哈哈牛 本文链接: http://blog.hahaniu.top/2018/05/25/webpack/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!