forked from caohenghu/vue-colorpicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (110 loc) · 3.19 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
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const path = require('path')
const minify = {
minifyCSS: true,
minifyJS: true,
removeComments: true, // 删除HTML中的注释
collapseWhitespace: true, // 删除空白符与换行符
collapseBooleanAttributes: true, // 省略布尔属性的值 <input checked="true"/> ==> <input checked />
removeEmptyAttributes: true, // 删除所有空格作属性值 <input id="" /> ==> <input />
removeScriptTypeAttributes: true, // 删除script上的type
removeStyleLinkTypeAttributes: true // 删除style上的type
}
module.exports = options => {
const env = require('./env/' + options.config + '.js')
const plugin = require('./env/pro.js').plugin
const port = env.port || 5555
const isLocal = options.local
const libs = []
const rules = [
{
test: /\.vue$/,
use: 'vue-loader'
},
// {
// test: /\.js$/,
// use: 'babel-loader'
// },
{
test: /\.scss$/,
use: [
isLocal ? 'vue-style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
},
{
test: /\.(png|jpg|gif|svg|ico)$/,
use: [
{
loader: 'url-loader',
options: {
name: 'images/[name]-[hash:8].[ext]',
limit: 1000
}
}
]
}
]
const plugins = [
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: './demo/index.ejs',
filename: 'index.html',
minify,
libs
})
]
if (isLocal) {
plugins.push(new webpack.HotModuleReplacementPlugin())
} else {
plugins.push(
new OptimizeCssAssetsPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name]-[hash:8].min.css'
})
)
}
// 如果是本地开发,使用未压缩的插件
if (isLocal) {
plugin.forEach((item, i) => {
plugin[i] = item.replace('.min', '')
})
}
plugin.forEach(item => {
libs.push({
url: item,
isAsync: false
})
})
return {
mode: isLocal ? 'development' : 'production',
entry: {
app: './demo'
},
output: {
publicPath: isLocal
? ''
: '//' + env.host.cdn + '/vue-colorpicker/',
path: path.resolve('dist'),
filename: isLocal ? 'js/[name].js' : 'js/[name]-[hash:8].js'
},
module: {
rules
},
plugins,
externals: {
vue: 'Vue'
},
devtool: options.pro ? false : 'source-map',
devServer: {
hot: true,
port
}
}
}