-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (100 loc) · 2.86 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
/**
* @file webpack 配置文件
* @author zhanglu
* @data 2018
*/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
module.exports = {
// 指定模式
mode: 'development',
// 项目入口
entry: path.join(__dirname, 'src/main.js'),
// 项目build后的文件地址
output: {
path: path.join(__dirname, 'dist'),
filename: 'js/main.[hash].js'
},
// 开发时助于debugger
devtool: 'source-map',
// webpack内置的node服务
devServer: {
// 根目录
contentBase: './',
inline: true,
// 端口
port: 3001,
// 启动gzip压缩
compress: false,
// 热更新
hot: true,
host: '0.0.0.0'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.(jpg|jpeg|gif|png|svg)$/,
loader: 'url-loader'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
loader: 'file-loader'
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
'sass-loader'
]
},
{
test: /\.md$/,
exclude: /node_modules/,
loader: 'babel-loader!markdown-it-react-loader'
}
]
},
plugins: [
// 生成html文件
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: 'body'
}),
// 提取css
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'css/[name].[hash].css',
chunkFilename: 'css/[id].[hash].css'
}),
// webpack热更新,不需要手动刷新页面
new webpack.HotModuleReplacementPlugin(),
// 清除dist文件
new CleanWebpackPlugin(['dist']),
// 复制静态文件到build后的文件夹
new CopyWebpackPlugin([
{
from: path.join(__dirname, '/src/static'),
to: path.join(__dirname, '/dist/static')
}
])
]
};