如何从加载程序中排除文件 [英] how to exclude files from loader

查看:32
本文介绍了如何从加载程序中排除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 webpack 加载器的下一个配置:

I have the next config for webpack loaders:

 module: {
    loaders: [{
      test: /\.js$/,
      include: rootDir + '/src',
      loader: 'babel?presets[]=es2015'
    }, {
      test: /\.css$/,
      loader: 'style!css!autoprefixer?browsers=last 2 versions'
    }, {
      test: /\.(png|gif|jpg|svg|ttf|eot|woff|woff2)$/,
      loader: 'file?name=[path][name].[ext]'
    }]
  }

我想从 autoprefixer 加载器中排除一些文件.我怎样才能做到这一点?如果我喜欢这个:

I want to exclude some files from autoprefixer loader. How can I do this? If I do like this:

{
  test: /\.css$/,
  exclude: 'someFile',
  loader: 'style!css!autoprefixer?browsers=last 2 versions'
}

someFile 不仅会从 autoprefixer 加载器中排除,还将从样式、css 和 autoprefixer 加载器中排除,但我只需要从 autoprefixer 加载器中排除文件.我该怎么做?

someFile will be excluded not only from autoprefixer loader, it will be excluded from styles, css and autoprefixer loader, but I need exclude file only from autoprefixer loader. How can I do this?

推荐答案

您走对了.创建两种加载器配置,一种用于somefile",另一种用于排除somefile"的其余 CSS 文件:

You're on the right track. Create two loader configurations, one for 'somefile', and one for the rest of your CSS files that excludes 'somefile':

module: {
  loaders: [
  ...
  {
    test: 'somefile',
    loader: 'style!css'
  }, {
    test: /\.css$/,
    loader: 'style!css!autoprefixer?browsers=last 2 versions',
    exclude: 'somefile'
  },
  ...
  ]
}

这篇关于如何从加载程序中排除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆