This repository has been archived by the owner on Apr 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.ts
162 lines (158 loc) · 4.39 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import path from "path";
import merge from "webpack-merge";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
import VueLoaderPlugin from "vue-loader/dist/plugin";
import Dotenv from "dotenv-webpack";
import { Configuration, Options } from "webpack";
const common: Configuration = {
entry: {
app: [
path.resolve(__dirname, "src/shims/shims.ts"),
path.resolve(__dirname, "src/index.ts")
]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].js"
},
resolve: {
extensions: [ ".js", ".ts", ".tsx" ],
alias: {
"stream": "stream-browserify",
"crypto": "crypto-browserify",
"vm": "vm-browserify"
}
},
module: {
rules: [
{
test: /\.tsx?$/u,
exclude: /node_modules/u,
use: "babel-loader"
},
{
test: /\.vue$/u,
exclude: /node_modules/u,
use: "vue-loader"
},
{
test: /\.(png|svg|jpg|gif)$/u,
include: path.resolve(__dirname, "src"),
use: [
{
loader: "url-loader",
options: {
fallback: "file-loader",
limit: 8192
}
},
{
loader: "img-loader",
}
]
},
{
test: /\.(ttf)$/u,
include: path.resolve(__dirname, "src"),
use: [
{
loader: "file-loader",
}
]
}
]
},
plugins: [
new Dotenv(),
// @ts-ignore
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, "src/index.html"),
base: "/"
}),
],
};
// @ts-ignore
const development: Configuration = {
mode: "development",
devtool: "cheap-module-source-map" as Options.Devtool,
module: {
rules: [
{
test: /\.css$/u,
use: [
"style-loader",
{
loader: "css-loader",
options: { importLoaders: 1 }
},
"postcss-loader"
]
},
]
}
};
// TODO: Use https://webpack.js.org/plugins/mini-css-extract-plugin/
const production: Configuration = {
mode: "production",
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
}),
],
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[contenthash].js"
},
module: {
rules: [
{
test: /\.css$/u,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: { esModule: true }
},
{
loader: "css-loader",
options: { importLoaders: 1 }
},
"postcss-loader"
]
},
]
},
optimization: {
runtimeChunk: "single",
noEmitOnErrors: true,
chunkIds: "natural",
minimize: true,
usedExports: false,
// minimizer: [
// new TerserPlugin({
// // cache does not work with Webpack 5
// // <https://webpack.js.org/plugins/terser-webpack-plugin/#cache>
// cache: false
// })
// ],
splitChunks: {
cacheGroups: {
vendor: {
name: "vendor",
test: /[/\\]node_modules[/\\]/u,
chunks: "all",
enforce: true,
priority: -10
}
}
}
}
};
export default merge(
common,
process.env.NODE_ENV === "development" ? development : production
);