2015-10-16 57 views
3

TL; DR:當生成兩個.js和一個.css塊時,該插件從.js塊之一中刪除所有.js代碼。extract-text-webpack-plugin刪除所有.js代碼

即使我僅使用webpack文檔中的示例,這也是可重複的行爲。

我可能失去了一些東西,但我找不到它是什麼:)

的配置如下:

var path = require('path'); 
var webpack = require('webpack'); 
var ExtractTextPlugin = require("extract-text-webpack-plugin"); 
var glob = require("glob"); 

module.exports = { 
    entry: { 
     app: [ 
      './.build/app/app_dependencys.js', 
      './.build/app/_helpers/api_helpers.js', 
      './.build/app/event-manager.js', 
      './.build/app/route_handlers/Router.js' 
     ], 
     lib: [ 
      'c3', 
      'lodash', 
      'moment', 
      'moment-timezone', 
      'pleasejs', 
      'react-bootstrap-datetimepicker', 
      'react', 
      'react-bootstrap', 
      'react-d3-components', 
      'react-datepicker-component', 
      'react-googlemaps', 
      'react-router', 
      'react-slider', 
      'reactable', 
      'select2' 
     ], 
     css: glob.sync('./css/css/*.styl') 
    }, 
    output: { 
     path: path.join(__dirname, 'js/dist'), 
     filename: "app.js", 
     chunkFilename: "[name].js" 
    }, 
    module: { 
     loaders: [ 
      {test: /\.jsx?$/, loader: 'babel?compact=false', ignore: /node_modules/}, 
      {test: /\.json$/, loader: "json"}, 
      { 
       test: /\.styl$/, 
       loader: ExtractTextPlugin.extract('raw', 'raw!stylus') 
      } 
     ] 
    }, 
    plugins: [ 
     new ExtractTextPlugin('id', "./../../css/compiled/css.css", {allChunks: false}), 
     new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"lib", /* filename= */"lib.js", Infinity) 
    ], 
    externals: ['jquery'], 
    bail: true 
}; 

當運行webpack,這是輸出:

Time: 51884ms 
         Asset  Size Chunks    Chunk Names 
         app.js 3.8 kB 0, 1 [emitted] app, css 
         lib.js 3.47 MB  2 [emitted] lib 
./../../css/compiled/css.css 131 kB  1 [emitted] css 
    [0] multi app 64 bytes {0} [built] 
    [0] multi css 364 bytes {1} [built] 
    [0] multi lib 196 bytes {2} [built] 
    + 634 hidden modules 
Child extract-text-webpack-plugin: 
     + 1 hidden modules 
Child extract-text-webpack-plugin: 
     + 1 hidden modules 
Child extract-text-webpack-plugin: 
     + 1 hidden modules 

.... it goes on for a while ... 

結果:

  • css.css包含了所有的CSS,根據需要
  • lib.js包含了所有的lib代碼,如需要
  • app.js:在app.js每一個條目被替換

    /***/ 581: 
    /***/ function(module, exports) { 
    
        // removed by extract-text-webpack-plugin 
    
    /***/ }, 
    
    /***/ 582: 
    /***/ function(module, exports) { 
    
         // removed by extract-text-webpack-plugin 
    
    /***/ }, 
    ... 
    

報告給插件作者以及:https://github.com/webpack/extract-text-webpack-plugin/issues/118

+0

我剛剛開始運行,因爲我在我的應用程序層次結構中將我的webpack文件移動到較低級別。你有沒有在這方面取得任何進展? –

+0

不好:(在這個問題上也幾乎沒有任何進展 – Mamut

+0

你可以嘗試一些建議張貼在那裏:https://github.com/webpack/extract-text-webpack-plugin/issues/118#issuecomment-213582249, https://github.com/webpack/extract-text-webpack-plugin/issues/118#issuecomment-223678580,https://github.com/webpack/extract-text-webpack-plugin/issues/118#issuecomment- 223689905 – Mamut

回答

1

答案在這裏: https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/118

好的,對我有效的是:好:條目:{js:'./js/app.js',css: './scss/main.scss'},bad:entry:{ js:'./js/app.js',scss: './scss/main.scss'}唯一的區別 - css鍵而不是scss。 並且還有條目:['./js/main.js','./scss/main.scss'],也起作用。

+0

你應該給更多的信息,鏈接是好的評論不是答案。 – Mitro