简体   繁体   English

如何从加载器中排除文件

[英]how to exclude files from loader

I have the next config for webpack loaders: 我有webpack加载器的下一个配置:

 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]'
    }]
  }

I want to exclude some files from autoprefixer loader. 我想从autoprefixer加载器中排除一些文件。 How can I do this? 我怎样才能做到这一点? If I do like this: 如果我喜欢这样:

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

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. someFile将被排除在autoprefixer加载器之外,它将被排除在样式,css和autoprefixer加载器之外,但我只需要从autoprefixer加载器中排除文件。 How can I do this? 我怎样才能做到这一点?

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': 创建两个加载器配置,一个用于'somefile',另一个用于排除'somefile'的其余CSS文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM