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
}
。
有什么不对吗?
答案 0 :(得分:0)
我的错误,entry
的格式错误,应该是:
entry: {
app: "./res/app/entry.js",
vendor: ["jquery"]
},