file-loader使用手册

2017-04-27  本文已影响723人  wuww

file-loader模块是webpack打包中用到的一个loader。
它实现的功能很简单:

配置

{
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'file-loader',
        query: {
          name: '[name].[ext]',
          outputPath: 'static/img/',
          publicPath: '/dist/static/img/'
        }
      }

name指定文件名
outputPath指定文件的输出目录,此处应为相对于webpack输出目录的相对路径。
publicPath指定请求文件时的URL。如上面的配置,生成的URL为/dist/static/img/${name}

注意
outputPath, publicPath一定要以/结尾

上一篇 下一篇

猜你喜欢

热点阅读