-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebpack.config.js
More file actions
99 lines (99 loc) · 2.55 KB
/
webpack.config.js
File metadata and controls
99 lines (99 loc) · 2.55 KB
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
const glob = require('glob')
const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')
const extractTextWebpackPlugin = require('extract-text-webpack-plugin')
const purifyCSSPlugin = require('purifycss-webpack')
module.exports = {
// mode: 'production',
mode: 'development',
entry: './src/main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: './assets/script/main.min.js',
// publicPath: 'http://127.0.0.1:6788/dist' // 绝对路径
},
module: {
rules: [
{ // es6
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
},
exclude: /node_modules/
},
{ // 处理js引入的css
test: /\.css$/,
use: extractTextWebpackPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
/*use: [
{loader: 'style-loader'},
{loader: 'css-loader' }
]*/
},
{ // 图片路径
test: /\.(png|jpg|gif|jpeg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 800, // Base64
name: '/assets/images/[hash].[ext]'
}
}]
},
{ // img标签路径
test: /\.(htm|html)$/i,
use: ['html-withimg-loader']
},
{ // sass编译
test: /\.sass$/,
use: extractTextWebpackPlugin.extract({
use: [
{loader: 'css-loader'},
{loader: 'sass-loader'}
],
fallback: 'style-loader'
})
},
/*{ // C3加前缀
test: /\.css$/,
use: extractTextWebpackPlugin.extract({
use: [
{loader: 'css-loader' },
{loader: 'postcss-loader'}
],
fallback: 'style-loader'
})
}*/
]
},
plugins: [
// 编译html模板
new htmlWebpackPlugin({
minify: {
removeAttributeQuotes: true // 却掉属性的双引号。
},
hash: true, // 混入hash避免缓存JS。
inject: 'body',
template: './src/index.html', //模版
filename: './index.html'
}),
// css独立抽离成文件
new extractTextWebpackPlugin('./assets/style/style.css'),
// 忽略无效css
new purifyCSSPlugin({
paths: glob.sync(path.join(__dirname, 'src/*.html'))
})
],
devServer: {
contentBase: path.resolve(__dirname, './dist'), // server目录
host: '127.0.0.1',
compress: true, // server压缩
port: 8888,
hot: true // 热加载
}
}