webpack.client.conf.js
2.63 KB
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
77
78
79
80
81
82
83
84
85
86
const webpack = require('webpack');
const path = require('path');
const merge = require('webpack-merge');
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin');
const pkg = require('../package.json');
// const shelljs = require('shelljs');
let baseConfig = require('./webpack.base.conf');
const postcssConfig = require('./postcss.config.js');
const isProd = process.env.NODE_ENV === 'production';
// if (process.env.NODE_ENV === 'production') {
// shelljs.exec(`cp -R ${path.join(__dirname, '../public/font/')} ${path.join(__dirname, '../src/statics/font/')}`, {async: true});
// shelljs.exec(`cp -R ${path.join(__dirname, '../public/img/')} ${path.join(__dirname, '../src/statics/img/')}`, {async: true});
// }
const webpackConfig = merge(baseConfig, {
entry: {
app: './src/entry-client.js'
},
devtool: isProd ? '#source-map' : '#cheap-module-source-map',
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: isProd,
postcss: {
plugins: postcssConfig.plugins,
options: postcssConfig
},
loaders: {
client: 'babel-loader'
}
}
}]
},
resolve: {
alias: {
'create-api': 'common/create-api-client.js'
}
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.VUE_ENV': '"client"'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function(module) {
return (
/node_modules/.test(module.context) &&
!/\.css$/.test(module.request)
);
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
}),
new VueSSRClientPlugin({
filename: `yoho-ssr-client-${pkg.version}.json`
})
]
});
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
parallel: true,
sourceMap: true,
uglifyOptions: {
compress: {
warnings: false
},
comments: false
}
}));
webpackConfig.output.publicPath = '//cdn.yoho.cn/yohoblk-wap/bundle/';
}
// let BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// webpackConfig.plugins.push(new BundleAnalyzerPlugin());
module.exports = webpackConfig;