@studyportals/webpack-helper 8.1.0 → 8.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +404 -389
- package/assets/.browserslistrc +2 -2
- package/dist/defaults/production.config.js +79 -0
- package/{src → dist}/factories/chunks-retry-plugin-factory.js +15 -17
- package/dist/interfaces/preset.interface.js +2 -0
- package/{src → dist}/model/configuration.js +2 -1
- package/{src → dist}/plugins/retry-chunk-load.plugin.js +35 -35
- package/dist/utils/cpus.js +29 -0
- package/package.json +55 -51
- package/src/defaults/production.config.js +0 -59
- /package/{src → dist}/defaults/development.config.js +0 -0
- /package/{src → dist}/enums/mode.js +0 -0
- /package/{src → dist}/enums/preset.js +0 -0
- /package/{src → dist}/factories/browser-list-to-esbuild-target-factory.js +0 -0
- /package/{src → dist}/factories/configuration-factory.js +0 -0
- /package/{src → dist}/interfaces/bob.interface.js +0 -0
- /package/{src → dist}/interfaces/chunks-retry.interface.js +0 -0
- /package/{src → dist}/interfaces/entry.interface.js +0 -0
- /package/{src → dist}/interfaces/entrypoint.interface.js +0 -0
- /package/{src/interfaces/output.interface.js → dist/interfaces/minify.interface.js} +0 -0
- /package/{src/interfaces/preset.interface.js → dist/interfaces/output.interface.js} +0 -0
- /package/{src → dist}/main.js +0 -0
- /package/{src → dist}/model/entry.js +0 -0
- /package/{src → dist}/model/module.js +0 -0
- /package/{src → dist}/model/output.js +0 -0
- /package/{src → dist}/model/plugins.js +0 -0
- /package/{src → dist}/presets/javascript.preset.js +0 -0
- /package/{src → dist}/presets/typescript.preset.js +0 -0
- /package/{src → dist}/presets/vue-typescript.preset.js +0 -0
package/README.md
CHANGED
|
@@ -1,389 +1,404 @@
|
|
|
1
|
-
# WebpackHelper
|
|
2
|
-
|
|
3
|
-
WebpackHelper is a utility that makes it easy to set up a webpack configuration for Studyportals' projects that adhere to our [Webpack quality criteria](https://knowledge-vault.studyportals.xyz/quality-standards/front-end/webpack-quality-criteria.html).
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Webpack version](#webpack-version)
|
|
8
|
-
- [Notes on updating Webpack from v4 to v5](#notes-on-updating-webpack-from-v4-to-v5)
|
|
9
|
-
- [Quick Start](#quick-start)
|
|
10
|
-
- [SCSS Migration](#scss-migration-from-153x-to--1540)
|
|
11
|
-
- [Minimum compiler that shows each warning](#minimum-compiler-that-shows-each-warning)
|
|
12
|
-
- [Migration](#migration)
|
|
13
|
-
- [List of changes](#list-of-changes)
|
|
14
|
-
- [Chunks Retry](#chunks-retry)
|
|
15
|
-
- [Defaults](#defaults)
|
|
16
|
-
- [Setup](#setup)
|
|
17
|
-
- [Limitations](#limitations)
|
|
18
|
-
- [Configuration](#configuration)
|
|
19
|
-
- [entry](#entry-required)
|
|
20
|
-
- [output](#output-required)
|
|
21
|
-
- [preset](#preset)
|
|
22
|
-
- [bob](#bob)
|
|
23
|
-
- [common](#common)
|
|
24
|
-
- [development](#development)
|
|
25
|
-
- [production](#production)
|
|
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
|
-
const
|
|
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
|
-
| `"sass
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
'@studyportals/multiselect/dist/multiselect.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
- `
|
|
287
|
-
- `
|
|
288
|
-
- `
|
|
289
|
-
- `
|
|
290
|
-
- `
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
- `
|
|
322
|
-
- `
|
|
323
|
-
- `
|
|
324
|
-
- `
|
|
325
|
-
- `
|
|
326
|
-
- `
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
1
|
+
# WebpackHelper
|
|
2
|
+
|
|
3
|
+
WebpackHelper is a utility that makes it easy to set up a webpack configuration for Studyportals' projects that adhere to our [Webpack quality criteria](https://knowledge-vault.studyportals.xyz/quality-standards/front-end/webpack-quality-criteria.html).
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Webpack version](#webpack-version)
|
|
8
|
+
- [Notes on updating Webpack from v4 to v5](#notes-on-updating-webpack-from-v4-to-v5)
|
|
9
|
+
- [Quick Start](#quick-start)
|
|
10
|
+
- [SCSS Migration](#scss-migration-from-153x-to--1540)
|
|
11
|
+
- [Minimum compiler that shows each warning](#minimum-compiler-that-shows-each-warning)
|
|
12
|
+
- [Migration](#migration)
|
|
13
|
+
- [List of changes](#list-of-changes)
|
|
14
|
+
- [Chunks Retry](#chunks-retry)
|
|
15
|
+
- [Defaults](#defaults)
|
|
16
|
+
- [Setup](#setup)
|
|
17
|
+
- [Limitations](#limitations)
|
|
18
|
+
- [Configuration](#configuration)
|
|
19
|
+
- [entry](#entry-required)
|
|
20
|
+
- [output](#output-required)
|
|
21
|
+
- [preset](#preset)
|
|
22
|
+
- [bob](#bob)
|
|
23
|
+
- [common](#common)
|
|
24
|
+
- [development](#development)
|
|
25
|
+
- [production](#production)
|
|
26
|
+
- [minify](#minify)
|
|
27
|
+
- [Presets](#presets)
|
|
28
|
+
- [javascript](#javascript)
|
|
29
|
+
- [typescript](#typescript)
|
|
30
|
+
- [vue-typescript](#vue-typescript)
|
|
31
|
+
- [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
|
|
32
|
+
|
|
33
|
+
## Webpack version
|
|
34
|
+
|
|
35
|
+
This version of WebpackHelper is based on webpack 5. Some earlier WebpackHelper versions used earlier versions of Webpack. If you get syntax errors when updating to the latest version of WebpackHelper, please check out the [Webpack documentation](https://webpack.js.org/configuration/).
|
|
36
|
+
|
|
37
|
+
### Notes on updating Webpack from v4 to v5
|
|
38
|
+
|
|
39
|
+
Below are some notes that might be helpful when you're upgrading a microservice from webpack-helper v2 (based on Webpack v4) to v3 (based on Webpack v5).
|
|
40
|
+
|
|
41
|
+
#### Exporting
|
|
42
|
+
|
|
43
|
+
Webpack-helper **v2 and below**: Your `webpack.config.js` file ended with the following:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
module.exports = mode => configuration.get(mode);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should end with the following (as is also mentioned further below):
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
module.exports = (env, details) => configuration.get(details.mode);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Quick Start
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm i -D @studyportals/webpack-helper
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
After installation, getting started is quite easy. Just set up a `webpack.config.js` file in the root of your project, require Webpack Helper and set up a configuration using it's `create` method like so:
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
const path = require('path');
|
|
65
|
+
const WebpackHelper = require("@studyportals/webpack-helper");
|
|
66
|
+
|
|
67
|
+
const configuration = WebpackHelper.create({
|
|
68
|
+
entry: [
|
|
69
|
+
"./src/main.ts"
|
|
70
|
+
],
|
|
71
|
+
output: {
|
|
72
|
+
path: path.resolve(__dirname, './dist'),
|
|
73
|
+
fileName: 'bundle',
|
|
74
|
+
hash: true,
|
|
75
|
+
// Use this if you want to control hashing for js and css separately
|
|
76
|
+
hash: {
|
|
77
|
+
js: true,
|
|
78
|
+
css: false
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
preset: "vue-typescript",
|
|
82
|
+
bob: {
|
|
83
|
+
name: 'MicroService',
|
|
84
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
85
|
+
baseURL: '/dist',
|
|
86
|
+
defer: ['style'],
|
|
87
|
+
dllPackages: [
|
|
88
|
+
{
|
|
89
|
+
name: "package-dll",
|
|
90
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
common: {
|
|
95
|
+
//any config
|
|
96
|
+
},
|
|
97
|
+
production: {
|
|
98
|
+
//any config
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
When your configuration is created you can get an instance of it for the correct environment and export it for webpack to use like so:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
module.exports = (env, details) => configuration.get(details.mode);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## SCSS Migration from 1.53.x to >= 1.54.0
|
|
110
|
+
|
|
111
|
+
This package is used by other services that build with `sass`. Each `sass` release is a JavaScript build of the same-numbered Dart Sass compiler, so bumping from 1.53.x to 1.54.0 silently enables a raft of breaking-change warnings. Eventually when Dart Sass 3 is released, these warnings become hard errors that will break downstream builds.
|
|
112
|
+
|
|
113
|
+
| Dependency in *package.json* | Real compiler behind the scenes | Notes |
|
|
114
|
+
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
|
|
115
|
+
| `"sass": "^1.89.2"` | Dart Sass 1.89.2 (JS build) | Running `npx sass --version` shows the exact Dart Sass version. |
|
|
116
|
+
| `"sass-loader": "^16"` | Webpack loader that invokes **whatever Sass implementation you installed** (defaults to the `sass` package above). | |
|
|
117
|
+
|
|
118
|
+
### Minimum compiler that shows each warning
|
|
119
|
+
|
|
120
|
+
| Change (see checklist below) | First **warns** in | Becomes an **error** |
|
|
121
|
+
| ---------------------------------------------- | ------------------ | -------------------- |
|
|
122
|
+
| Invalid combinators (`> >`, leading `+`, etc.) | 1.54.0 | already errors |
|
|
123
|
+
| Media-Query Level 4 logic | 1.54.0 | 1.56.0 |
|
|
124
|
+
| Strict unary `+ -` spacing | 1.55.0 | already errors |
|
|
125
|
+
| Duplicate `!default`/`!global` flags | 1.62.0 | already errors |
|
|
126
|
+
| Reserved `type()` function | 1.86.0 | next major |
|
|
127
|
+
| `/` division → `math.div()` | 1.33.0 | next major |
|
|
128
|
+
| `@import` → module system | 1.80.0 | Dart Sass 3 |
|
|
129
|
+
|
|
130
|
+
### Migration
|
|
131
|
+
|
|
132
|
+
To help us migrate, there is a package called `sass-migrator` that you can use to resolve the majority of the issues.
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm install --save-dev sass-migrator
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Then run
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# migrate @import → @use/@forward
|
|
142
|
+
npx sass-migrator module --migrate-deps "src/**/*.scss"
|
|
143
|
+
|
|
144
|
+
# replace “/” division with math.div()
|
|
145
|
+
npx sass-migrator division --migrate-deps "src/**/*.scss"
|
|
146
|
+
|
|
147
|
+
# add the required space for ambiguous + / - operators
|
|
148
|
+
npx sass-migrator strict-unary --migrate-deps "src/**/*.scss"
|
|
149
|
+
|
|
150
|
+
# swap legacy color helpers (lighten(), darken(), …) for sass:color APIs
|
|
151
|
+
npx sass-migrator color --migrate-deps "src/**/*.scss"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
#### List of changes
|
|
155
|
+
|
|
156
|
+
| # | Change you must make | **Before — old SCSS** | **After — new SCSS** | Why it matters |
|
|
157
|
+
| -- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
158
|
+
| 1 | Replace **`@import` → `@use/@forward`** | A) `@import "tools/colors";`<br>B) `@import "theme/light";`<br> `@import "components/button";` | A) `@use "tools/colors" as colors;`<br>B) `@use "theme/light" as *;`<br> `@use "components/button";` | `@import` builds a huge global namespace and re-parses files; removed in Dart Sass 3.0. |
|
|
159
|
+
| 2 | Slash-division → **`math.div()`** | A) `width: 100%/3;`<br>B) `$col: 940px/12;` | `@use "sass:math";`<br>A) `width: math.div(100%, 3);`<br>B) `$col: math.div(940px, 12);` | `/` is being re-defined as a list separator. |
|
|
160
|
+
| 3 | Make unary `+` / `-` unambiguous | A) `gap: 10px -$space;`<br>B) `margin: +$n ($n*2);` | A) `gap: 10px - $space;` or `gap: 10px (-$space);`<br>B) `margin: + $n (#{$n*2});` | Compiler now errors on ambiguous signs. |
|
|
161
|
+
| 4 | Rename a custom **`type()`** function | A) `@function type($x) {…}`<br>B) `$v: type(42);` | A) `@function kind($x) {…}`<br>B) `$v: kind(42);` | CSS adds its own reserved `type()`. |
|
|
162
|
+
| 5 | Swap legacy colour helpers for **`sass:color`** | A) `$hover: lighten($brand, 10%);`<br>B) `$new: adjust-hue($brand, 20deg);` | `@use "sass:color";`<br>A) `$hover: color.adjust($brand, $lightness: 10%);`<br>B) `$new: color.adjust($brand, $hue: 20deg);` | Old helpers assume sRGB only. |
|
|
163
|
+
| 6 | Remove duplicate flags | A) `$pad: 1rem !default !default;`<br>B) `$debug: null !global !global;` | `$pad: 1rem !default;`<br>`$debug: null !global;` | A second `!default`/`!global` is now an error. |
|
|
164
|
+
| 7 | Delete **`meta.feature-exists()`** | A) `@use "sass:meta";`<br> `@if meta.feature-exists("global-variable-shadowing") {…}`<br>B) `$has: feature-exists(calc);` | Usually just delete — all features it checks are always present. | Function is obsolete. |
|
|
165
|
+
| 8 | Fix stray / doubled combinators | A) `+ .alert {…}`<br>B) `nav > > li {…}` | A) `.alert {…}`<br>B) `nav > li {…}` | Invalid CSS selectors now error. |
|
|
166
|
+
| 9 | Keep declarations **before** nested rules | `.card {`<br> `color:#333;`<br> `&__header {…}`<br> `font-weight:bold;`<br>`}` | `.card {`<br> `color:#333;`<br> `&__header {…}`<br> `& { font-weight:bold; }`<br>`}` | Mirrors CSS Nesting source-order rules. |
|
|
167
|
+
| 10 | Use CSS-4 logic in **`@media`** | A) `@media (not (prefers-reduced-motion)) {…}`<br>B) `@media ((hover) and (pointer:fine)) {…}` | `@media not (prefers-reduced-motion) {…}`<br>`@media (hover) and (pointer:fine) {…}` | Old parenthesised syntax conflicts with MQ L4. |
|
|
168
|
+
| 11 | Always interpolate custom-prop values | A) `--accent: $brand;`<br>B) `--size: $gap * 1.5;` | `--accent: #{$brand};`<br>`--size: #{$gap * 1.5};` | Stops Sass mistaking raw CSS tokens for vars. |
|
|
169
|
+
| 12 | Give colour funcs the right units | A) `hsl(0.5turn,100%,50%);`<br>B) `$deg: 90grad; hue($c,$deg);` | A) `hsl(180deg,100%,50%);`<br>B) `$deg: 90deg; color.adjust($c,$hue:$deg);` | Functions now enforce CSS-spec units. |
|
|
170
|
+
| 13 | Use **`math.abs()`** for percentages | A) `$pos: abs(-10%);`<br>B) `padding: abs(5%);` | `@use "sass:math";`<br>A) `$pos: math.abs(-10%);`<br>B) `padding: math.abs(5%);` | Global `abs()` drops `%` support. |
|
|
171
|
+
| 14 | Rename any name starting **`--`** | A) `@mixin --theme($c){…}`<br>B) `@function --shadow(){…}` | `@mixin _theme($c){…}`<br>`@function _shadow(){…}` | `--` reserved for future native CSS mixins. |
|
|
172
|
+
| 15 | Remove special **`@-moz-document`** parser | `@-moz-document url-prefix("https://") { … }`<br>`@-moz-document domain(mozilla.org) { … }` | *(Delete or treat as an unknown at-rule; only `@-moz-document url-prefix()` hack still compiles.)* | Feature gone from Firefox → dropped from Sass. |
|
|
173
|
+
| 16 | **Don’t `@extend` a compound selector** | A) `.notice { @extend .msg.info; }`<br>B) `.alert { @extend .box.error; }` | `.notice { @extend .msg, .info; }`<br>`.alert { @extend .box, .error; }` | Dart Sass forbids extending `.foo.bar`. |
|
|
174
|
+
| 17 | **You can’t overwrite a mixin or function that came in via `@use`** | `@import "~@studyportals/styles-abstracts/abstracts.scss";`<br>`@include TextStyle($name);`<br>`font-weight: 700;`| `@use "~@studyportals/styles-abstracts/abstracts.scss" as *;`<br>`@include TextStyle($name);`| Error immediately since `@use` (1.23) — name collisions are blocked ([sass-lang.com][1]) |
|
|
175
|
+
|
|
176
|
+
[1]: https://sass-lang.com/blog/the-module-system-is-launched/ "Sass: The Module System is Launched"
|
|
177
|
+
|
|
178
|
+
## Chunks Retry
|
|
179
|
+
|
|
180
|
+
Webpack Helpers has a default configuration to retry chunks which cannot get loaded on the first try (for whatever reason, network or otherwise).
|
|
181
|
+
|
|
182
|
+
It has an Exponential Backoff to calculate the delay between retries of a maximum of `2` seconds.
|
|
183
|
+
|
|
184
|
+
The functionality is implemented thru a plugin called `webpack-retry-chunk-load-plugin` <https://www.npmjs.com/package/webpack-retry-chunk-load-plugin>.
|
|
185
|
+
|
|
186
|
+
### Defaults
|
|
187
|
+
|
|
188
|
+
By default it is enabled if the selected preset is `vue-typescript` and it uses `6` as the number of retries it does and it uses the `rollbar` instance on the `window` object (Portal instance) to log an error when it reaches the threshold of retries without being able to load the chunk (`new Error('Failed to load chunk for after retries')`).
|
|
189
|
+
|
|
190
|
+
### Setup
|
|
191
|
+
|
|
192
|
+
To configure the functionality you can provide an object following this interface
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
interface IChunksRetryPluginConfig {
|
|
196
|
+
inject: boolean; //if you want the plugin injected
|
|
197
|
+
|
|
198
|
+
threshold: number; //amount of retries
|
|
199
|
+
|
|
200
|
+
thresholdReachedCallBack?: string; //a function (body of it as string) to be called when the amount of retries has been exhausted
|
|
201
|
+
|
|
202
|
+
rollbarInstanceIdentifier?: string; //a key of a Rollbar instance present on the 'window' object e.g if you want to use window['rollbar_PQ'] to track the error in the Profile Questionnaire project in Rollbar then you send 'rollbar_PQ'
|
|
203
|
+
|
|
204
|
+
disableDefaultRollbarError?: boolean; //if you don't want to log by default when the threshold has been reached
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
and you can provide this thru the `webpack` config of your service like so
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
const configuration = WebpackHelper.create({
|
|
212
|
+
chunksRetryConfig: {
|
|
213
|
+
threshold: 10,
|
|
214
|
+
thresholdReachedCallBack: `console.log("hello")`,
|
|
215
|
+
},
|
|
216
|
+
...
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Limitations
|
|
220
|
+
|
|
221
|
+
We have some limitations in this implementation based on the plugin we used and that the code will be part of the webpack exported code
|
|
222
|
+
|
|
223
|
+
### Only use ES5
|
|
224
|
+
|
|
225
|
+
You can only write ES5 code inside the `thresholdReachedCallBack`
|
|
226
|
+
|
|
227
|
+
### String as function
|
|
228
|
+
|
|
229
|
+
The function `thresholdReachedCallBack` must be a string (aka the body of the function) and we cannot change that to be a function while retaining the simplicity of the code.
|
|
230
|
+
|
|
231
|
+
## Configuration
|
|
232
|
+
|
|
233
|
+
Webpack Helper offers a compact but flexible configuration interface. Below you will find every option available.
|
|
234
|
+
|
|
235
|
+
### entry **(required)**
|
|
236
|
+
|
|
237
|
+
The entrypoint for your webpack bundle. This can either be configured as an object with the bundle name as a key and the path as a value or as an array of paths if your project requires multiple entry points.
|
|
238
|
+
|
|
239
|
+
```javascript
|
|
240
|
+
entry: [
|
|
241
|
+
"./src/main.ts"
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
//or
|
|
245
|
+
|
|
246
|
+
entry: {
|
|
247
|
+
bundle: "./src/main.ts"
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Working with packaged components & libraries
|
|
252
|
+
|
|
253
|
+
When working with packaged components and libraries it is required to keep the bundle name in line with the major version of the package. This helps to prevent reference issues when multiple versions of a package load on a single page.
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
// version 1
|
|
257
|
+
entry: {
|
|
258
|
+
multiselect_v1: "./src/main.ts"
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// version 2
|
|
262
|
+
entry: {
|
|
263
|
+
multiselect_v2: "./src/main.ts"
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### DLL
|
|
268
|
+
|
|
269
|
+
When working with a packaged component as a DLL, both the JS bundle and CSS bundle from the core package must be referenced, as below:
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
|
|
273
|
+
entry: {
|
|
274
|
+
multiselect_v2: [
|
|
275
|
+
'@studyportals/multiselect/dist/multiselect.js',
|
|
276
|
+
'@studyportals/multiselect/dist/multiselect.css'
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### output **(required)**
|
|
283
|
+
|
|
284
|
+
The output object has some options that define how your bundle will be output. It has the following properties:
|
|
285
|
+
|
|
286
|
+
- `path`**(required)**: The target directory for all output files.
|
|
287
|
+
- `library`: The name of the exported library, which will also be used to namespace sourcemaps. This will default to `null`.
|
|
288
|
+
- `publicPath`: The url to the output directory resolved relative to the HTML page. This will default to `null`.
|
|
289
|
+
- `fileName`: A custom filename for your bundle. This will default to `[name]` which refers to the name you've given your entrypoint.
|
|
290
|
+
- `hash`: Whether or not to add build hashes to your filenames. This will default to `true`. Whenever you want different values for your js and css you can pass an object with separate properties and values as in the example below.
|
|
291
|
+
- `crossOriginLoading`: Tells webpack to enable cross-origin loading of chunks. Can either be set to `anonymous` or `user-credentials`.
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
output: {
|
|
295
|
+
path: path.resolve(__dirname, './dist'),
|
|
296
|
+
library: 'test-microservice',
|
|
297
|
+
publicPath: '/assets/',
|
|
298
|
+
fileName: 'application',
|
|
299
|
+
crossOriginLoading: 'anonymous',
|
|
300
|
+
hash: false,
|
|
301
|
+
//or
|
|
302
|
+
hash: {
|
|
303
|
+
js: true,
|
|
304
|
+
css: false
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### preset
|
|
310
|
+
|
|
311
|
+
The preset property determines which preset to load into your webpack configuration.
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
preset: "vue-typescript | typescript | javascript"
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### bob
|
|
318
|
+
|
|
319
|
+
The bob object adds all necessary configuration to have your project generate a manifest file to be used by [Bob](https://github.com/studyportals/Bob).
|
|
320
|
+
|
|
321
|
+
- `name`**(required)**: The name of your microservice.
|
|
322
|
+
- `html`**(required)**: The HTML that needs to be output by your microservice. Can be a path to a document or a snippet.
|
|
323
|
+
- `baseURL`: The baseURL for your microservice assets.
|
|
324
|
+
- `async`: An array of JS filenames to be loaded async.
|
|
325
|
+
- `defer`: An array of CSS filenames to be lazy-loaded.
|
|
326
|
+
- `exclude`: An array of filenames (CSS and JS) that should be excluded from your manifest file.
|
|
327
|
+
- `dllPackages`: An array of objects that reference your Dll dependencies. They all require a name and a Dll manifest in the form of a json file.
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
bob: {
|
|
331
|
+
name: 'MicroService',
|
|
332
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
333
|
+
baseURL: '/dist',
|
|
334
|
+
defer: ['style'],
|
|
335
|
+
exclude: ['demo-assets'],
|
|
336
|
+
dllPackages: [
|
|
337
|
+
{
|
|
338
|
+
name: "package-dll",
|
|
339
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
WebpackHelper uses [BobManifestGenerator](https://github.com/studyportals/BobManifestGenerator) to generate a manifest file.
|
|
346
|
+
|
|
347
|
+
### common
|
|
348
|
+
|
|
349
|
+
Extra Webpack configuration to be used for all environments can be passed in the `common` object. This configuration needs to adhere to Webpack's configuration interface and will be merged in with the other configuration through [webpack-merge](https://github.com/survivejs/webpack-merge).
|
|
350
|
+
|
|
351
|
+
### development
|
|
352
|
+
|
|
353
|
+
Extra Webpack configuration to be used for all development builds can be passed in the `development` object. This configuration needs to adhere to Webpack's configuration interface and will be merged in with the other configuration through [webpack-merge](https://github.com/survivejs/webpack-merge).
|
|
354
|
+
|
|
355
|
+
**NOTE**: Some default configuration for development builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
356
|
+
|
|
357
|
+
### production
|
|
358
|
+
|
|
359
|
+
Extra Webpack configuration to be used for all production builds can be passed in the `production` object. This configuration needs to adhere to Webpack's configuration interface and will be merged in with the other configuration through [webpack-merge](https://github.com/survivejs/webpack-merge).
|
|
360
|
+
|
|
361
|
+
**NOTE**: Some default configuration for production builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
362
|
+
|
|
363
|
+
### minify
|
|
364
|
+
|
|
365
|
+
Controls how production builds are minified. Every property is optional.
|
|
366
|
+
|
|
367
|
+
```javascript
|
|
368
|
+
minify: {
|
|
369
|
+
minifier: 'terser', // 'terser' (default, smallest output) or 'esbuild' (several times faster, ~8 % larger gzipped JS)
|
|
370
|
+
passes: 2, // Terser compress passes (default 2; more passes barely shrink the output but cost a lot of build time)
|
|
371
|
+
css: 'cssnano' // 'cssnano' (default) or 'lightningcss' (faster, about the same output size, but it fails on some legacy CSS)
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
The minifiers use every CPU the build can use. That count respects container CPU limits (cgroups), so a CI container with 4 vCPUs uses 4 workers even if the host has more. Set `WEBPACK_PARALLELISM` to override it. The build logs the minifiers and the CPU count it uses.
|
|
376
|
+
|
|
377
|
+
## Presets
|
|
378
|
+
|
|
379
|
+
In order to make your life as easy as possible, Webpack Helper ships with a set of presets that will take care of putting some essential plugins and loaders in your configuration. The different presets are listed below.
|
|
380
|
+
|
|
381
|
+
More in depth information on what configuration these presets will add to your project can be found [here](src/presets/presets.md).
|
|
382
|
+
|
|
383
|
+
### javascript
|
|
384
|
+
|
|
385
|
+
The javascript preset will resolve all `.js` and `.json` files and transpiles them with Babel. If your project has styling, it will separate that out in a separate `.css` file.
|
|
386
|
+
|
|
387
|
+
### typescript
|
|
388
|
+
|
|
389
|
+
The typescript preset will resolve all `.ts`, `.tsx`, `.js` and `.json` files. It transpiles them using tsc and Babel. Be aware that you will need to include a `tsconfig.json` in your project for it to work properly. If your project has styling, it will separate that out in a separate `.css` file.
|
|
390
|
+
|
|
391
|
+
### vue-typescript
|
|
392
|
+
|
|
393
|
+
The vue-typescript preset will resolve all `.vue`, `.ts`, `.tsx`, `.js` and `.json` files. It transpiles them using vue-loader, tsc and Babel. Be aware that you will need to include a `tsconfig.json` in your project for it to work properly. If your project has styling, it will separate that out in a separate `.css` file.
|
|
394
|
+
|
|
395
|
+
## DoD compliance with Babel and Browserslist
|
|
396
|
+
|
|
397
|
+
In order to comply to [Studyportals' definition of done](https://knowledge-vault.studyportals.xyz/definitions-of-done/product/) we use `babel` to transpile our front-end code according to the browsers we need to support. To do this your project needs some configuration. When Webpack Helper is installed it will put standard configuration in the root of your project which consists of 2 files:
|
|
398
|
+
|
|
399
|
+
- `.babelrc`: A standard configuration for babel that loads the `babel-env` and `babel-typescripts` presets. You might need to add more plugins for your specific project.
|
|
400
|
+
- `.browserslistrc`: A configuration file for browserslist. This is used by `babel-env` to determine which browsers to transpile the code for. Within this file the configuration for student facing products will be loaded by default but other configurations can be easily loaded by uncommenting some lines.
|
|
401
|
+
|
|
402
|
+
## Unit testing
|
|
403
|
+
|
|
404
|
+
From version `6.0.0` onwards test dependencies are no longer included and should be installed separately. It's also recommended to replace jest with vitest due the complex nature of package jungle. A upgrade guide can be find [here](docs/jest-to-vitest-upgrade-guide.md)
|