-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.prod.config.js
76 lines (65 loc) · 1.92 KB
/
webpack.prod.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* 生产环境
*/
var path = require('path');
var webpack = require('webpack');
var merge = require('webpack-merge');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpackBaseConfig = require('./webpack.base.config.js');
var fs = require('fs');
var utils = require('./utils')
var CopyWebpackPlugin = require('copy-webpack-plugin')
process.env.NODE_ENV = '"production"';
module.exports = merge(webpackBaseConfig, {
entry: {
main: './src/main',
vendors: ['vue', 'vue-router'],
},
output: {
path: path.join(__dirname, './dist'),
publicPath: '',
filename: 'js/[name].[hash].js',
chunkFilename: 'chunk/[name].[hash].chunk.js',
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': process.env.NODE_ENV,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_debugger: true,
drop_console: true
}
}),
new HtmlWebpackPlugin({
filename: './index.html',
template: path.join(__dirname,'src/template/index.ejs'),
inject: false,
hash: false
}),
new webpack.optimize.CommonsChunkPlugin({name: 'vendors', filename: 'js/vendor.bundle.[hash].js'}),
// new ExtractTextPlugin({filename: 'css/[name].css', allChunks: true}),
new CopyWebpackPlugin(
[
{
from :path.resolve(__dirname,'src/static/js/ea.min.js'),
to:path.resolve(__dirname,'dist','js/ea.min.js')
}
]
,{
copyUnmodified: true
}),
function () {
this.plugin("done", function (stats) {
var buildConfig = path.join(__dirname,'./dist/js/config.js')
fs.open(buildConfig, 'w', function (err, fd) {
var buf = `window.globalConfigs = ${JSON.stringify(utils.resolve(require('./index')), null, 4)}`;
console.log(buf)
fs.writeSync(fd, buf, 0, buf.length, 0);
utils.after('./dist',stats.compilation.assets,stats.hash)
});
})
}
]
});