排除webpack加载器中的目录

Dav*_*vid 11 webpack

我正在尝试在我的webpack项目中使用css-modules,但我也在使用包中的一些css node_modules.如何编写一个加载器只使用我module目录中的模块而不是目录中的模块node_modules?我尝试了以下但它是borks.看起来它正试图将模块的东西应用到css中node_modules.

  {
    test: /\.css$/,
    loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
    include: [
      path.resolve(__dirname, 'modules')
    ]
  },
  { 
    test: /\.css$/, 
    loader: 'style!css',
    include: [
      path.resolve(__dirname, 'node_modules')
    ]
  },
Run Code Online (Sandbox Code Playgroud)

小智 5

exclude对于那些现在发现这一点的人(像我一样),我通过在 webpack 配置中定义补充规则来实现这一点:

{
  test: /\.css$/,
  loader: 'css-loader',
  exclude: /my_app_client_dir/,
  query: {
    modules: true,
    localIdentName: '[local]' // no funny stuff with node_modules resources
  }
},
{
  test: /\.css$/,
  exclude: /node_modules/,
  loader: 'css-loader',
  query: {
    modules: true,
    localIdentName: '[name]__[local]___[hash:base64:5]'
  }
}
Run Code Online (Sandbox Code Playgroud)

当在两个加载器上没有排除规则的情况下编写此内容时,我从 webpack 中收到了编译错误。

  • 如何在此处排除多个文件夹...`排除:[ /images/, /node_modules/ ]` 我已经使用了上面的代码,但不适合我。 (8认同)

sma*_*sma -1

您还可以排除 node_modules 目录:

{
    test: /\.css$/, 
    loader: 'style!css',
    exclude: /node_modules/,
}
Run Code Online (Sandbox Code Playgroud)

  • 如何在此处排除多个文件夹...`排除:[ /images/, /node_modules/ ]` 我已经使用了上面的代码,但不适合我 (13认同)