美文网首页
file-loader使用手册

file-loader使用手册

作者: wuww | 来源:发表于2017-04-27 14:15 被阅读723次

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

  • 将要加载的文件复制到指定目录
  • 生成请求文件资源URL

配置

{
        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一定要以/结尾

相关文章

网友评论

      本文标题:file-loader使用手册

      本文链接:https://www.haomeiwen.com/subject/wfmgzttx.html