-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.ts
115 lines (112 loc) · 2.42 KB
/
webpack.config.ts
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
import * as path from 'path';
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as Webpack from 'webpack';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
const VueLoaderPlugin = require('vue-loader/lib/plugin-webpack5');
console.log('process.env.NODE_ENV :>> ', process.env.NODE_ENV);
export default {
entry: ['@babel/polyfill', './src/main.ts'],
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.css|sass|scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['postcss-preset-env', {}]],
},
},
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.ts|js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
],
},
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
},
],
},
{
// webpack5 内置了 asset 模块, 用来代替 file-loader & url-loader & raw-loader 处理静态资源
test: /\.png|jpg|gif|jpeg|svg/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
},
generator: {
filename: 'images/[base]',
},
},
{
test: /\.txt|xlsx/,
type: 'asset',
generator: {
filename: 'files/[base]',
},
},
],
},
plugins: [
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: 'src/index.html',
}),
new Webpack.HotModuleReplacementPlugin(),
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
new Webpack.ProvidePlugin({
Vue: ['vue/dist/vue.esm.js', 'default'],
}),
new Webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
],
resolve: {
extensions: ['.ts', '.js', '.vue'],
plugins: [
// 将 tsconfig 中配置的路径别名映射到 webpack.resolve.alias 上
new TsconfigPathsPlugin(),
],
},
devtool:
process.env.NODE_ENV === 'development' ? 'eval-source-map' : 'source-map',
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
open: true,
port: 8888,
compress: true,
hot: true,
clientLogLevel: 'silent',
noInfo: true,
},
} as Webpack.Configuration;