2017-09-06 60 views
0

我正试图将在node_modules目录中找到的所有CSS文件提取到一个文件中。我的WebPack配置如下:如何将所有CSS文件包含在由css-loader构建的node_modules中?

{  // node_modules css in /node_modules/**/*.css 
    test: /\.css$/, 
    include: /node_modules/, 
    // extract to the node modules css file 
    use: ExtractTextPluginNodeMods.extract({ 
     fallback: 'style-loader', 
     use: [ 
     { 
      loader: 'css-loader', 
      options: { 
      modules: false, 
      }, 
     }, 
     ], 
    }), 
} 

不幸的是,没有在node_modules目录中的CSS文件正在捆绑与ExtractTextPluginNodeMods指定的文件。我有另一个ExtractTextPlugin实例成功地从我的src目录中提取CSS。任何想法为什么我无法从node_modules中提取CSS?

仅供参考,我的其他ExtractTextPlugin /的WebPack配置(这是捆绑所有的 CSS是在这里:

{ 
    // OUR css in /src/ 
    // the css output from sass loader will be caught here 
    // fonts are imported by css loader 
    // after transpiling of sass -> css, css-loader in webpack should take care of this 
    // https://github.com/webpack-contrib/css-loader 
    test: /\.css$/, 
    exclude: /node_modules/, 
    // extract to our css file 
    use: ExtractTextPluginSrc.extract({ 
     fallback: 'style-loader', 
     use: [ 
     { 
      loader: 'css-loader', 
      // create modular css with the '[name]__[local]___[hash:base64:5]' 
      options: { 
      modules: true, 
      localIdentName: '[name]__[local]___[hash:base64:5]', 
      }, 
     }, 
     'postcss-loader', 
     ], 
    }), 
    } 

回答

0

的WebPack将不包括CSS文件,除非你明确地从您的JavaScript代码导入所以你需要:

import 'some_package/css/component.css'; 

在您的应用程序,它使用的CSS部分

Alternat。结构延续,你可以使用类似的glob-装载机做

import 'glob-loader?node_modules_pattern_file'; 

,然后让“node_modules_pattern_file”包括像

../node_modules/**/*.css 

一个水珠......但我不推荐这种方法,因为你”最终会导致大量不需要的文件,并且很难维护。

相关问题