-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
78 lines (75 loc) · 2.02 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
/*
* @Description: This is a webpack config file
* @Author: JeanneWu
* @Date: 2020-03-17 11:28:09
*/
// js文件头部注释之后的内容
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
const vueLoaderPlugin = require('vue-loader/lib/plugin')
const webpack = require('webpack')
const moduleConfig = env => {
// Use env.<YOUR VARIABLE> here:
console.log('NODE_ENV: ', env.NODE_ENV) // 'production' 根据此处判断环境
console.log('Production: ', env.production) // ture
return {
entry: "./src/main.js",
output: {
filename: 'main.js',
path: path.resolve('__dirname', 'dist')
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(gif|jpg|jpeg|svg)/,
use: [{
loader: 'url-loader',
options: {
limit: 1024,
name: '[name].[hash:6].[ext]'
}
}, ]
}]
},
plugins: [
new htmlWebpackPlugin(),
new vueLoaderPlugin()
]
}
}
const devConfigFun = (argument)=> {
argument.devtool = '#cheap-module-eval-source-map';
argument.devServer = {
port: '8000',
host: '0.0.0.0',
overlay: {
errors: true
},
open: true,
hot: true
}
argument.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
return argument;
}
module.exports = env => {
let config = moduleConfig(env)
if (env.NODE_ENV === 'development'){
config = devConfigFun(config)
}
return config
}