2015-10-15 69 views
0

webpack.config.js的WebPack把供应商大块大块的应用程序与鲍尔使用

var path = require("path"); 
var webpack = require("webpack"); 
module.exports = { 
    entry: "./res/app/entry.js", 
    vendor: ["jquery"], 
    output: { 
     path: __dirname + "/res/js/", 
     filename: "app.js" 
    }, 
    module: { 
     loaders: [ 
      {test: /\.css$/, loader: "style!css"} 
     ] 
    }, 
    resolve: { 
     root: [path.join(__dirname, "bower_components")] 
    }, 
    plugins: [ 
     new webpack.ResolverPlugin(
      new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"]) 
     ), 
     new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js") 
    ] 
}; 

bower.json时:

{ 
    "name": "webapp", 
    "version": "0.0.0", 
    "license": "MIT", 
    "ignore": [ 
    "**/.*", 
    "node_modules", 
    "bower_components", 
    "test", 
    "tests" 
    ], 
    "devDependencies": { 
    "jquery": "~1.11" 
    }, 
    "resolutions": { 
    "jquery": "~1.11" 
    } 
} 

RAN webpack后,会生成两个文件:

app.js(the application chunk) 

vendor.bundle.js(vendor chunk) 

但是jquery放在app.js里面,应该在vendor.bundle.js

有什么问题吗?

回答

0

我的错误,entry的格式是错误的,它应该是:

entry: { 
    app: "./res/app/entry.js", 
    vendor: ["jquery"] 
},