2017-09-22 4 views
0
私はコンポーネント(コンポーネントごとに)同じフォルダにJSとCSSを維持リアクト作成したい

js bundleからcssを削除するには?

  • Container.jsx
  • Presentation.jsx
  • styles.less
    • ダイアログ

ここは私のwebpack conの一部ですイチジク:

module: { 
    loaders: [ 
     { 
      test: /\.(js|jsx)$/, 
      loader: 'babel', 
      exclude: /(node_modules)/, 
      query: { 
       presets: [ 
        ['react'], 
        ['es2015'], 
        ['stage-0'] 
       ], 
       plugins: [ 
        ['transform-decorators-legacy'], 
        ['transform-runtime'], 
        ['transform-react-remove-prop-types'], 
        ['transform-react-constant-elements'], 
        ['transform-react-inline-elements'] 
       ] 
      } 
     }, 
     { 
      test: /\.less$/, 
      loader: ExtractTextPlugin.extract(['css-loader', 'less-loader']), 
     } 
    ], 
}, 
plugins: [ 
    new webpack.NoEmitOnErrorsPlugin(), 
    new webpack.DefinePlugin({ 
     'process.env.NODE_ENV': '"production"' 
    }), 
    new webpack.ProvidePlugin({ 
     'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch' 
    }), 
    new webpack.optimize.UglifyJsPlugin({ 
     beautify: false, 
     comments: false, 
     sourceMap: true, 
     compress: { 
      sequences: true, 
      booleans: true, 
      loops: true, 
      unused: true, 
      warnings: false, 
      drop_console: true, 
      unsafe: true 
     } 
    }), 
    new ExtractTextPlugin({ 
     filename: 'bundle.css', 
     allChunks: true 
    }), 
    new OptimizeCssAssetsPlugin({ 
     assetNameRegExp: /\.css$/g, 
     cssProcessor: require('cssnano'), 
     cssProcessorOptions: { 
      discardComments: { 
       removeAll: true 
      } 
     }, 
     canPrint: true 
    }) 
], 

のWebPACKはbundle.js + bundle.cssファイルを作成します。私はそれが1瞬間を除いて期待どおりに機能すると言います。 bundle.jsには、bundle.cssのCSSが含まれています。

たとえば、bundle.cssのサイズが50KBの場合、bundle.js =自分のサイズ+ 50KB。

jsバンドルに重複したCSSコードは必要ありません。どのようにそれを修正するには?

答えて

0

laravel-elixir-webpack-officialからネイティブwebpack(webpack-stream)に変更したときに修正されました

関連する問題