forked from fwon/gulp-webpack-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
50 lines (47 loc) · 1.32 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var path = require('path');
var webpack = require('webpack');
var fs = require('fs');
var uglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var srcDir = path.resolve(process.cwd(), 'src');
//获取多页面的每个入口文件,用于配置中的entry
function getEntry() {
var jsPath = path.resolve(srcDir, 'js');
var dirs = fs.readdirSync(jsPath);
var matchs = [], files = {};
dirs.forEach(function (item) {
matchs = item.match(/(.+)\.js$/);
console.log(matchs);
if (matchs) {
files[matchs[1]] = path.resolve(srcDir, 'js', item);
}
});
console.log(JSON.stringify(files));
return files;
}
module.exports = {
cache: true,
devtool: "source-map",
entry: getEntry(),
output: {
path: path.join(__dirname, "dist/js/"),
publicPath: "dist/js/",
filename: "[name].js",
chunkFilename: "[chunkhash].js"
},
resolve: {
alias: {
jquery: srcDir + "/js/lib/jquery.min.js",
core: srcDir + "/js/core",
ui: srcDir + "/js/ui"
}
},
plugins: [
new CommonsChunkPlugin('common.js'),
new uglifyJsPlugin({
compress: {
warnings: false
}
})
]
};