-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
63 lines (62 loc) · 1.57 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
let path = require('path');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let CleanWebpackPlugin = require('clean-webpack-plugin');
let webpack = require('webpack');
let ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
let cssExtract = new ExtractTextWebpackPlugin({
filename: 'css/css.css',
});
let CopyWebpackPlugin = require('copy-webpack-plugin');
let PurifycssWebpack = require('purifycss-webpack');
let glob = require('glob');
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].[hash:8].js',
path: path.resolve('./build')
},
devServer: {
contentBase: './build',
port: 3000,
compress: true,
open: true,
hot: true
},
plugins: [
cssExtract,
// 拷贝插件
new CopyWebpackPlugin([
{
from: './src/doc',
to: 'public'
}
]),
new webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(['./build']),
new HtmlWebpackPlugin({
template: './src/index.html',
title: 'webpack',
hash: true,
}),
// 没用的css会被消除掉,一定放在htmlwebpackPlugin后面
new PurifycssWebpack({
paths:glob.sync(path.resolve('src/*.html'))
})
],
mode: 'development',
resolve: {},
module: {
rules: [ // 从右往左写
{
test: /\.css$/, use: cssExtract.extract({
fallback:'style-loader',
use: [
{ loader: 'css-loader' },
{loader:'postcss-loader'}
]
})
}
]
}
}
// 1.抽离样式 抽离到一个css文件 通过css文件的方式来引用