-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
167 lines (161 loc) · 4.43 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
163
164
165
166
167
import path from "path";
import webpack from "webpack";
import TerserPlugin from "terser-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import FileManagerPlugin from "filemanager-webpack-plugin";
// const isProduction = process.env.NODE_ENV == "production";
// Config UDM
const configUDM: webpack.Configuration = {
mode: "production",
devtool: "source-map",
entry: {
"webcimes-tooltip.udm": "./src/ts/webcimes-tooltip.ts",
},
output: {
filename: "js/[name].js",
path: path.resolve(__dirname, "dist"),
libraryTarget: "umd",
clean: false, // Clean the output directory before emit.
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js$/i,
extractComments: false,
}),
],
},
module: {
rules: [
{
test: /\.(ts)$/i,
use: "ts-loader",
},
],
},
plugins: [
new FileManagerPlugin({
events: {
onStart: {
delete: [
"./dist/js",
],
},
onEnd: {
copy: [
{ source: "./src/ts/webcimes-tooltip.d.ts", destination: './dist/js/webcimes-tooltip.udm.d.ts' },
],
},
},
}),
],
};
// Config ESM
const configESM: webpack.Configuration = {
mode: "production",
devtool: "source-map",
entry: {
"webcimes-tooltip.esm": "./src/ts/webcimes-tooltip.ts",
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js$/i,
extractComments: false,
}),
],
},
experiments: {
outputModule: true,
},
output: {
filename: "js/[name].js",
path: path.resolve(__dirname, "dist"),
libraryTarget: "module",
clean: false, // Clean the output directory before emit.
},
module: {
rules: [
{
test: /\.(ts)$/i,
use: "ts-loader",
},
],
},
plugins: [
new FileManagerPlugin({
events: {
onStart: {
delete: [
"./dist/js",
],
},
onEnd: {
copy: [
{ source: "./src/ts/webcimes-tooltip.d.ts", destination: './dist/js/webcimes-tooltip.esm.d.ts' },
],
},
},
}),
],
};
// Config CSS + Remove plugin
const configCSS: webpack.Configuration = {
mode: "production",
devtool: "source-map",
entry: {
"webcimes-tooltip": "./src/css/webcimes-tooltip.css",
},
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin({
test: /\.css$/i,
}),
],
},
output: {
filename: "css/[name].js",
path: path.resolve(__dirname, "dist"),
clean: false, // Clean the output directory before emit.
},
module: {
rules: [
{
test: /\.css$/i,
// use: ['style-loader', 'css-loader'],
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(svg|png|jpg|jpeg|gif)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext][query]', // Correct bug asset/ressource url wrong path with css files subfolder https://github.com/webpack-contrib/mini-css-extract-plugin/issues/1005
},
},
],
},
plugins: [
new MiniCssExtractPlugin({ filename: "css/[name].css" }),
new FileManagerPlugin({
events: {
onStart: {
delete: [
"./dist/css",
],
},
onEnd: {
delete: [
"./dist/css/webcimes-tooltip.js",
"./dist/css/webcimes-tooltip.js.map",
],
}
},
}),
],
};
// Export
export default [configUDM, configESM, configCSS];