-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
119 lines (104 loc) · 2.46 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
117
118
119
//webpack
const path = require('path')
const webpack = require('webpack') //webpack 插件
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') //抽离 css 文件,使用这个插件需要单独配置JS和CSS压缩
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') //压缩JS
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') //压缩CSS
module.exports = {
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true
}),
new OptimizeCSSAssetsPlugin()
]
},
mode: 'development',
devtool: 'source-map',
//入口
entry: {
index: './app/index.tsx'
},
//出口
output: {
filename: '[name].js',
path: path.resolve(__dirname, './dist'),
library: 'react-lister', // 类库名称
libraryTarget: 'umd' // 类库打包方式
},
resolve: {
modules: [path.resolve('node_modules')],
alias: {
'~': path.resolve(__dirname, './app')
},
extensions: ['.js', '.jsx', '.ts', '.tsx', '.scss', '.css'] //配置省略后缀名
},
// 不打包 react 和 react-dom
externals: {
react: 'react',
'react-dom': 'react-dom'
},
//规则
module: {
rules: [{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
},
{
test: /\.(scss|sass)$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
{
loader: 'sass-loader',
options: {
includePaths: ['./node_modules/normalize-scss/sass']
}
}
]
},
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: ['ts-loader']
},
{
test: /\.(jpg|png|gif|jpeg|bmp|eot|svg|ttf|woff|woff2)$/,
use: {
loader: 'url-loader',
options: {
limit: 20 * 1024,
outputPath: './',
}
}
}
]
},
//插件
plugins: [
new MiniCssExtractPlugin({
filename: 'lister.css'
})
],
watch: true,
watchOptions: {
poll: 2000,
aggregateTimeout: 2000,
ignored: /node_modules|vendor|build|public|resources/
},
devServer: {
port: 8080,
progress: true,
contentBase: './dist',
open: true,
historyApiFallback: true,
}
}