-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.client.js
138 lines (131 loc) · 3.1 KB
/
webpack.config.client.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const path = require('path')
const HTMLPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const merge = require('webpack-merge')
const baseConfig = require('./webpack.config.base')
const VueClientPlugin = require('vue-server-renderer/client-plugin')
// const cdnConfig = require('../app.config').cdn
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const isDev = process.env.NODE_ENV === 'development'
const defaultPluins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: isDev ? '"development"' : '"production"'
}
}),
new HTMLPlugin({
template: path.join(__dirname, 'template.html')
}),
new VueClientPlugin(),
new VueLoaderPlugin()
]
const devServer = {
port: 8080,
host: '0.0.0.0',
overlay: {
errors: true
},
headers: { 'Access-Control-Allow-Origin': '*' },
historyApiFallback: {
index: '/public/index.html'
},
// proxy: {
// '/api': 'http://127.0.0.1:3333',
// '/user': 'http://127.0.0.1:3333'
// },
hot: true
}
let config
if (isDev) {
config = merge(baseConfig, {
mode: 'none',
devtool: '#cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.less/,
use: [
'vue-style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
'less-loader'
]
}
]
},
devServer,
plugins: defaultPluins.concat([
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
])
})
} else {
config = merge(baseConfig, {
entry: {
app: path.join(__dirname, '../client/client-entry.js'),
vendor: ['vue']
},
output: {
filename: '[name].[chunkhash:8].js',
// publicPath: cdnConfig.host
publicPath: '/public/'
},
module: {
rules: [
{
test: /\.less/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
'less-loader'
]
}
]
},
plugins: defaultPluins.concat([
new MiniCssExtractPlugin({
filename: "styles.[chunkhash:8].css"
// chunkFilename: "[id].css"
}),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor'
// }),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'runtime'
// }),
new MiniCssExtractPlugin({
filename: "styles.[chunkhash:8].css"
// chunkFilename: "[id].css"
}),
new webpack.NamedChunksPlugin()
]),
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor'
}
}
}
}
})
}
config.resolve = {
alias: {
'model': path.join(__dirname, '../client/model/client-model.js')
}
}
module.exports = config