使用bower时,webpack将供应商块放到app chunk

时间:2015-10-15 00:09:54

标签: webpack

webpack.config.js

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"
  }
}

运行webpack后,会生成两个文件:

app.js(the application chunk)

vendor.bundle.js(vendor chunk)

但是jquery放在app.js内,vendor.bundle.js应该在if (/\b[\da-z]{7,14}\b/.test(subject)) { // Successful match } else { // Match attempt failed }

有什么不对吗?

1 个答案:

答案 0 :(得分:0)

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

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