Repository navigation
Expand file tree
/
Copy pathwebpack.config.mjs
More file actions
203 lines (196 loc) · 5.16 KB
/
Copy pathwebpack.config.mjs
File metadata and controls
203 lines (196 loc) · 5.16 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { fileURLToPath } from 'url'
import path from 'path'
import TerserPlugin from 'terser-webpack-plugin'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
// `npm run coverage` builds the library with istanbul counters so that the browser exposes window.__coverage__ for the tests to harvest
const coverageInstrumentation = process.argv.includes('coverage')
? {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: '@jsdevtools/coverage-istanbul-loader'
}
]
}
: undefined
export default [
// esm
{
name: 'main',
entry: './semanticForms.js',
output: {
// development mode labels every module in the bundle with a comment naming its path, e.g. /*! ./lib/helpers.js */, which is noise to anyone reading this build and does not survive being bundled again cleanly: the /*! marks it as a license, so the minifier of a project that bundles this one moves every label out into a *.LICENSE.txt file of its own
pathinfo: false,
path: path.join(__dirname, 'dist'),
filename: 'semantic-forms.mjs',
library: {
type: 'module'
},
globalObject: 'this',
umdNamedDefine: true
},
experiments: {
outputModule: true
},
mode: 'development',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: false,
unused: true
},
mangle: false,
format: {
comments: 'all'
}
}
})
]
}
},
// commonjs
{
name: 'main',
entry: './semanticForms.js',
output: {
// development mode labels every module in the bundle with a comment naming its path, e.g. /*! ./lib/helpers.js */, which is noise to anyone reading this build and does not survive being bundled again cleanly: the /*! marks it as a license, so the minifier of a project that bundles this one moves every label out into a *.LICENSE.txt file of its own
pathinfo: false,
path: path.join(__dirname, 'dist'),
filename: 'semantic-forms.cjs',
library: 'semanticForms',
libraryTarget: 'umd',
globalObject: 'this',
umdNamedDefine: true
},
mode: 'development',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: false,
unused: true
},
mangle: false,
format: {
comments: 'all'
}
}
})
]
},
// the docs site the tests run against bundles dist/semantic-forms.cjs, so this is the build that has to carry the counters for a coverage run to measure anything
module: coverageInstrumentation
},
// standalone (directly includable in a <script> tag)
{
name: 'main',
entry: './semanticForms.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'semantic-forms.js',
library: 'semanticForms',
libraryTarget: 'umd',
globalObject: 'this',
umdNamedDefine: true
},
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: false,
unused: true
},
mangle: false,
format: {
comments: 'all'
}
}
})
]
}
},
// esm minified
{
name: 'main',
entry: './semanticForms.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'semantic-forms.min.mjs',
library: {
type: 'module'
}
},
experiments: {
outputModule: true
},
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: true,
unused: true
},
mangle: true,
format: {
comments: false
}
}
})
]
}
},
// standalone (directly includable in a <script> tag) minified
{
name: 'main',
entry: './semanticForms.js',
output: {
path: path.join(__dirname, 'dist'),
filename: 'semantic-forms.min.js',
library: 'semanticForms',
libraryTarget: 'umd',
globalObject: 'this',
umdNamedDefine: true
},
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
defaults: true,
unused: true
},
mangle: true,
format: {
comments: false
}
}
})
]
}
}
]