2016-01-03 50 views
1

我正在使用ionic2 + angular2。我想將自己的代碼放在一個文件中,並將所有庫合併到另一個文件中。webpack CommonsChunkPlugin不能正常工作

問題是我自己的應用程序仍然包含庫。

image

這是我的配置文件:

var path = require('path'); var webpack = require("webpack"); 

module.exports = { root: path.resolve('/'), 
devtool: 'source-map', 
entry: { 

    vendor:[path.normalize('es6-shim/es6-shim.min'), 
     'reflect-metadata', 
     'web-animations.min', 
     'zone.js/dist/zone-microtask', 
     'ionic-framework/ionic' 
    ], 
    app: path.resolve('www/app/app.ts') 
    }, 
output: { 
    filename: '[name].js', 
}, 
plugin:[ 
    new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 
           'vendor.js', minChunks: Infinity }), 
], 
module: { 
    loaders: [ 
     { 
     test: /\.ts$/, 
     loader: 'awesome-typescript', 
     query: { 
      'doTypeCheck': false 
     }, 
     include: path.resolve('www/app'), 
     exclude: /node_modules/ 
     }, 
     { 
     test: /\.js$/, 
     include: path.resolve('node_modules/angular2'), 
     loader: 'strip-sourcemap' 
     }, 
     { test: /\.html$/, loader: 'raw-loader' }, 
    ], 
    noParse: [ 
     /es6-shim/, 
     /reflect-metadata/, 
     /web-animations/, 
     /zone\.js(\/|\\)dist(\/|\\)zone-microtask/ 
    ] }, resolve: { 
    alias: { 
     'web-animations.min': path.normalize('ionic-framework/js/web-animations.min') 
    }, 
    extensions: ["", ".ts", ".js" ] } }; 
+0

我解決了這個問題,我是使用插件單數而不是插件 –

回答

0

我想你忘了爲vendor進入指定angular2ionic2模塊:

entry: { 
    vendor:[ 
     path.normalize('es6-shim/es6-shim.min'), 
     'reflect-metadata', 
     'web-animations.min', 
     'zone.js/dist/zone-microtask', 
     'ionic-framework/ionic', 

     // HERE: add all "angular2" and "ionic2" modules you're using 
     'angular2/platform/browser', 
     'angular2/core', 
     'angular2/router', 
     // and so on... 
    ], 

    // ... 
} 
+0

非常感謝@alexpods, 我已經試圖插入angular2,但沒有工作, 我看到angular2庫在兩個文件(供應商和應用程序)沒有插入angular2,coz ionic2將在webpack建設期間調用angular2 –

+0

我解決了它,我被使用插件單數而不是插件,謝謝@alexpods –