forked from GoldWorker/SluckyUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.testdev.js
194 lines (193 loc) · 6.99 KB
/
webpack.testdev.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-05-27 17:35:26
* @LastEditTime: 2019-05-27 17:35:26
* @LastEditors: your name
*/
const path = require('path');
const ExtractTextWebapckPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const sassExtract = new ExtractTextWebapckPlugin('./slucky.css');
const UglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// 图表分析
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
// const Autoprefixer = require('autoprefixer')
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
const ENV_CONF = require('./environment/dev.env.ts');
//构建前删除dist目录 const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
devtool: 'source-map',
//出口配置
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkHash].js',
chunkFilename: '[name].[chunkHash].js'
// publicPath: '/public'
},
//module.rules 加载loaders
module: {
rules: [{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
// { test: /\.scss$/, exclude: /node_modules/, use:
// sassExtract.extract({ fallback: 'style-loader', use:
// ['css-loader', 'postcss-loader', 'sass-loader'] }) },
{
test: /\.scss$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
},
{
test: /\.less$/,
exclude: /node_modules/,
use: ['css-hot-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'less-loader']
}, {
test: /.jsx$/, //使用loader的目标文件。这里是.jsx
loader: 'babel-loader'
}, {
test: /\.js/,
use: {
loader: 'babel-loader',
query: {
presets: ['env', 'stage-0']
}
},
exclude: /node_modules/
},
{
test: /\.svg$/,
include: [path.resolve(__dirname, 'src/icons')],
use: [{
loader: 'svg-sprite-loader',
options: {
symbolId: 'icon-[name]'
}
},
'svg-fill-loader', {
loader: 'svgo-loader',
options: {
plugins: [{
removeTitle: true
}, {
convertColors: {
shorthex: false
}
}, {
convertPathData: false
}]
}
}
]
},
{
test: /\.(jpg|png|gif|svg|jpeg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 8192,
mimetype: 'image/png',
fallback: 'responsive-loader',
quality: 100
}
}],
include: path.join(__dirname, './src'),
exclude: [
path.resolve(__dirname, 'src/icons'),
path.resolve(__dirname, '/node_modules/')
]
}, {
test: /\.(eot|ttf|woff)$/,
use: 'file-loader'
}, {
test: /\.(html|htm)$/,
use: 'html-withimg-loader'
}, {
test: /\.md$/,
use: [{
loader: 'html-loader'
},
{
loader: 'markdown-loader',
options: {
/* your options here */
}
}
]
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: { // 抽离第三方插件
test: /node_modules/, // 指定是node_modules下的第三方包
chunks: 'initial',
name: 'vendor', // 打包后的文件名,任意命名
// 设置优先级,防止和自定义的公共代码提取时被覆盖,不进行打包
priority: 10
},
commons: { // 抽离自己写的公共代码,commons这个名字可以随意起
chunks: 'initial',
name: 'commons', // 任意命名
minSize: 0 // 只要超出0字节就生成一个新包
}
}
}
},
//插件
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(ENV_CONF)
}),
// new BundleAnalyzerPlugin(),
new CleanWebpackPlugin('dist', {
verbose: false,
watch: true,
'exclude': ['.git']
}), //打包前先清空
new MiniCssExtractPlugin({
filename: 'slucky.css'
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'), //模板
filename: 'index.html',
// chunks:['index'],
hash: true, //防止缓存
title: 'slucky',
minify: {
removeAttributeQuotes: true, //压缩 去掉引号
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true
}
}),
require('autoprefixer'),
new UglifyjsWebpackPlugin({
uglifyOptions: {
ie8: false,
mangle: true,
output: {
comments: false
},
compress: {
warnings: false,
drop_console: true,
drop_debugger: true,
unused: false
}
},
sourceMap: true,
cache: true
}),
// sassExtract,
new webpack.HotModuleReplacementPlugin(),
new webpack.HashedModuleIdsPlugin()
]
};