-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
165 lines (146 loc) · 3.75 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
const isPro = NODE_ENV === 'production';
const confName = process.env.NODE_BUILD_CONF_NAME || 'dev';
const conf = require('./config/' + confName);
const setup = require('./setup');
const sortDistName = 'lr-client';
var bundleName = sortDistName + '.js';
if(isPro){
bundleName = sortDistName + '.min.js';
}
var optimization;
const outputPath = path.join(__dirname, conf.indexDir, '/dist/');
const publicPath = conf.baseUrl + '/dist/';
var cssRule;
if(confName === 'dev' && !isPro){ //使用 命令weblack
cssRule = {
test: /(\.scss$)|(\.css$)/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
include: path.join(__dirname, './src')
}
}else{
cssRule = {
test: /(\.scss$)|(\.css$)/,
//use: ["css-loader", "postcss-loader", "sass-loader"]
use: [
{
loader: MiniCssExtractPlugin.loader
},
"css-loader", 'postcss-loader', "sass-loader"
]
}
}
// var indexData = conf.indexData || {};
// indexData.BASE_URL = conf.baseUrl;
// indexData.VERSION = package.version;
// ***************************** plugins *****************************
var plugins = [
new VueLoaderPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(NODE_ENV)
}
}),
// create index.html
// new HtmlWebpackPlugin({
// chunksSortMode: 'dependency',
// filename: path.join(__dirname, conf.indexDir + '/index.html'),
// template: path.join(__dirname, '/src/index.ejs'),
// nodeModuleStatic : setup.nodeModuleStatic,
// indexData
// })
]
var rules = [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.jade$/,
loader: 'pug-plain-loader'
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
cssRule
]
// ***************************** 环境适配 *****************************
if (isPro) {
optimization = {
minimizer: [
new TerserPlugin(),
new OptimizeCSSAssetsPlugin({})
]
}
plugins = plugins.concat([//正式环境下压缩
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: sortDistName + ".min.css",
// chunkFilename: "chunk_[id]_[contenthash].css"
}),
// new webpack.optimize.TerserPlugin({
// compress: {
// warnings: false,
// },
// sourceMap: false,
// output: {
// comments: false,
// }
// }),
new webpack.LoaderOptionsPlugin({
minimize: true
})
]);
// -------- pre lint --------
rules.unshift({
enforce: "pre",
test: /(\.js|\.vue)$/,
include: [path.resolve(__dirname, "src")],
loader: "eslint-loader"
})
};
// ***************************** conf *****************************
const webpackConf = {
mode: NODE_ENV,
optimization,
context: path.join(__dirname, './src'),
entry: {
z_app: "./app.js"
},
output: {
path: outputPath,
publicPath,
filename: bundleName,
// chunkFilename: chunkName
},
module: {
rules
},
resolve: {
extensions: ['.js'],
alias: {
'__ROOT__' : path.join(__dirname, './src')
}
},
plugins: plugins,
devServer: {
before: setup,
host: '127.0.0.1',
onListening: setup.wsProxyHandle,
contentBase: path.join(__dirname, conf.indexDir),
hot: true
},
performance: {
hints: false
}
};
module.exports = webpackConf;