2017-09-06 63 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 

一個水珠......但我不推薦這種方法,因爲你」最終會導致大量不需要的文件,並且很難維護。

相關問題