-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
62 lines (59 loc) · 1.57 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
51
52
53
54
55
56
57
58
59
60
61
62
var path = require('path');
var webpack = require('webpack');
var fs = require('fs');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var srcDir = path.resolve(process.cwd(), 'src');
//获取多页面的每个入口文件,用于配置中的entry
function getEntry() {
var jsPath = path.resolve(srcDir, 'scripts');
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, 'scripts', item);
}
});
console.log(JSON.stringify(files));
return files;
}
module.exports = {
cache: true,
devtool: "source-map", //生成sourcemap,便于开发调试
entry: getEntry(),
output: {
path: path.join(__dirname, "dist/scripts/"),
publicPath: "dist/scripts/",
filename: "[name].js",
chunkFilename: "[chunkhash].js"
},
module: {
loaders: [{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015']
}
}]
},
plugins: [
new CommonsChunkPlugin('common.js'),
new UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.ProvidePlugin({ // 默认所有文件引入jquery
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
externals: { // 定义全局变量
// require('data') is external and available
'anthor': 'yll'
}
};