2017-09-06 3 views
0

node_modulesディレクトリにあるすべてのCSSファイルを1つのファイルに展開しようとしています。css-loaderによって構築されるnode_modulesにすべてのCSSファイルを含めるには?

{  // 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で指定したファイルにバンドルされていないされている次のように私のWebPACKの設定です。私はsrcディレクトリからCSSを正常に抽出している別のExtractTextPluginインスタンスを持っています。なぜ私はCSSの抽出をnode_modulesから得ることができないのでしょうか?参考のため

、私の他の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は、明示的にあなたのjavascriptのコードからそれらをインポートしない限り、CSSファイルは含まれません。だから、必要があります

import 'some_package/css/component.css'; 

CSSを使用して、あなたのアプリの一部に

Alternat。あなたは

import 'glob-loader?node_modules_pattern_file'; 

を行い、その後、あなたの「node_modules_pattern_file」を持っている

../node_modules/**/*.css 

などのグロブを含めグロブローダーのようなものを使用することができively ...しかし、私はこの方法をお勧めしませんあなたのために」あなたが必要としないファイルをたくさん引っ張ってしまい、それを維持するのが難しくなります。

関連する問題