@studyportals/webpack-helper 7.0.0-2 → 7.0.0-3
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 +105 -111
- package/package.json +2 -2
- package/src/defaults/development.config.js +5 -4
- package/src/model/configuration.js +1 -1
package/README.md
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
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
4
|
|
|
5
5
|
## Table of Contents
|
|
6
|
+
|
|
6
7
|
- [Webpack version](#webpack-version)
|
|
7
8
|
- [Notes on updating Webpack from v4 to v5](#notes-on-updating-webpack-from-v4-to-v5)
|
|
8
9
|
- [Quick Start](#quick-start)
|
|
9
10
|
- [Chunks Retry](#chunks-retry)
|
|
10
11
|
- [Defaults](#defaults)
|
|
11
|
-
- [
|
|
12
|
+
- [Setup](#setup)
|
|
12
13
|
- [Limitations](#limitations)
|
|
13
14
|
- [Configuration](#configuration)
|
|
14
15
|
- [entry](#entry-required)
|
|
@@ -16,57 +17,33 @@ WebpackHelper is a utility that makes it easy to set up a webpack configuration
|
|
|
16
17
|
- [preset](#preset)
|
|
17
18
|
- [bob](#bob)
|
|
18
19
|
- [common](#common)
|
|
20
|
+
- [staticPath](#staticpath-required)
|
|
19
21
|
- [development](#development)
|
|
20
22
|
- [production](#production)
|
|
21
23
|
- [Presets](#presets)
|
|
22
24
|
- [javascript](#javascript)
|
|
23
25
|
- [typescript](#typescript)
|
|
24
26
|
- [vue-typescript](#vue-typescript)
|
|
25
|
-
- [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
|
|
27
|
+
- [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
|
|
26
28
|
|
|
27
29
|
## Webpack version
|
|
30
|
+
|
|
28
31
|
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/).
|
|
29
32
|
|
|
30
33
|
### Notes on updating Webpack from v4 to v5
|
|
31
|
-
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).
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
Webpack-helper **v2 and below**: Your `development.devServer` file might include these parts:
|
|
35
|
-
```javascript
|
|
36
|
-
{
|
|
37
|
-
development: {
|
|
38
|
-
devServer: {
|
|
39
|
-
open: true,
|
|
40
|
-
overlay: true,
|
|
41
|
-
writeToDisk: true
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should configure those parts like this:
|
|
47
|
-
```javascript
|
|
48
|
-
{
|
|
49
|
-
development: {
|
|
50
|
-
devServer: {
|
|
51
|
-
client: {
|
|
52
|
-
overlay: true
|
|
53
|
-
},
|
|
54
|
-
devMiddleware: {
|
|
55
|
-
writeToDisk: true
|
|
56
|
-
},
|
|
57
|
-
open: true,
|
|
58
|
-
static: path.join(__dirname, '.') // Related to writeToDisk.
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
```
|
|
35
|
+
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).
|
|
63
36
|
|
|
64
37
|
#### Exporting
|
|
38
|
+
|
|
65
39
|
Webpack-helper **v2 and below**: Your `webpack.config.js` file ended with the following:
|
|
40
|
+
|
|
66
41
|
```javascript
|
|
67
42
|
module.exports = mode => configuration.get(mode);
|
|
68
43
|
```
|
|
44
|
+
|
|
69
45
|
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should end with the following (as is also mentioned further below):
|
|
46
|
+
|
|
70
47
|
```javascript
|
|
71
48
|
module.exports = (env, details) => configuration.get(details.mode);
|
|
72
49
|
```
|
|
@@ -84,41 +61,40 @@ const path = require('path');
|
|
|
84
61
|
const WebpackHelper = require("@studyportals/webpack-helper");
|
|
85
62
|
|
|
86
63
|
const configuration = WebpackHelper.create({
|
|
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
|
-
}
|
|
64
|
+
entry: [
|
|
65
|
+
"./src/main.ts"
|
|
66
|
+
],
|
|
67
|
+
output: {
|
|
68
|
+
path: path.resolve(__dirname, './dist'),
|
|
69
|
+
fileName: 'bundle',
|
|
70
|
+
hash: true,
|
|
71
|
+
// Use this if you want to control hashing for js and css separately
|
|
72
|
+
hash: {
|
|
73
|
+
js: true,
|
|
74
|
+
css: false
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
preset: "vue-typescript",
|
|
78
|
+
bob: {
|
|
79
|
+
name: 'MicroService',
|
|
80
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
81
|
+
baseURL: '/dist',
|
|
82
|
+
defer: ['style'],
|
|
83
|
+
dllPackages: [
|
|
84
|
+
{
|
|
85
|
+
name: "package-dll",
|
|
86
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
common: {
|
|
91
|
+
//any config
|
|
92
|
+
},
|
|
93
|
+
//needed for webpack-dev-server configuration
|
|
94
|
+
staticPath: path.join(__dirname, "."),
|
|
95
|
+
production: {
|
|
96
|
+
//any config
|
|
97
|
+
}
|
|
122
98
|
});
|
|
123
99
|
```
|
|
124
100
|
|
|
@@ -129,29 +105,32 @@ module.exports = (env, details) => configuration.get(details.mode);
|
|
|
129
105
|
```
|
|
130
106
|
|
|
131
107
|
## Chunks Retry
|
|
108
|
+
|
|
132
109
|
Webpack Helpers has a default configuration to retry chunks which cannot get loaded on the first try (for whatever reason, network or otherwise).
|
|
133
110
|
|
|
134
111
|
It has an Exponential Backoff to calculate the delay between retries of a maximum of `2` seconds.
|
|
135
112
|
|
|
136
|
-
The functionality is implemented thru a plugin called `webpack-retry-chunk-load-plugin` https://www.npmjs.com/package/webpack-retry-chunk-load-plugin
|
|
113
|
+
The functionality is implemented thru a plugin called `webpack-retry-chunk-load-plugin` <https://www.npmjs.com/package/webpack-retry-chunk-load-plugin>.
|
|
137
114
|
|
|
138
115
|
### Defaults
|
|
139
116
|
|
|
140
117
|
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')`).
|
|
141
118
|
|
|
142
|
-
###
|
|
119
|
+
### Setup
|
|
120
|
+
|
|
143
121
|
To configure the functionality you can provide an object following this interface
|
|
122
|
+
|
|
144
123
|
```js
|
|
145
124
|
interface IChunksRetryPluginConfig {
|
|
146
|
-
|
|
125
|
+
inject: boolean; //if you want the plugin injected
|
|
147
126
|
|
|
148
|
-
|
|
127
|
+
threshold: number; //amount of retries
|
|
149
128
|
|
|
150
|
-
|
|
129
|
+
thresholdReachedCallBack?: string; //a function (body of it as string) to be called when the amount of retries has been exhausted
|
|
151
130
|
|
|
152
|
-
|
|
131
|
+
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'
|
|
153
132
|
|
|
154
|
-
|
|
133
|
+
disableDefaultRollbarError?: boolean; //if you don't want to log by default when the threshold has been reached
|
|
155
134
|
}
|
|
156
135
|
```
|
|
157
136
|
|
|
@@ -159,20 +138,23 @@ and you can provide this thru the `webpack` config of your service like so
|
|
|
159
138
|
|
|
160
139
|
```js
|
|
161
140
|
const configuration = WebpackHelper.create({
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
141
|
+
chunksRetryConfig: {
|
|
142
|
+
threshold: 10,
|
|
143
|
+
thresholdReachedCallBack: `console.log("hello")`,
|
|
144
|
+
},
|
|
145
|
+
...
|
|
167
146
|
```
|
|
168
147
|
|
|
169
148
|
### Limitations
|
|
149
|
+
|
|
170
150
|
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
|
|
171
151
|
|
|
172
152
|
### Only use ES5
|
|
153
|
+
|
|
173
154
|
You can only write ES5 code inside the `thresholdReachedCallBack`
|
|
174
155
|
|
|
175
156
|
### String as function
|
|
157
|
+
|
|
176
158
|
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.
|
|
177
159
|
|
|
178
160
|
## Configuration
|
|
@@ -185,41 +167,43 @@ The entrypoint for your webpack bundle. This can either be configured as an obje
|
|
|
185
167
|
|
|
186
168
|
```javascript
|
|
187
169
|
entry: [
|
|
188
|
-
|
|
170
|
+
"./src/main.ts"
|
|
189
171
|
]
|
|
190
172
|
|
|
191
173
|
//or
|
|
192
174
|
|
|
193
175
|
entry: {
|
|
194
|
-
|
|
176
|
+
bundle: "./src/main.ts"
|
|
195
177
|
}
|
|
196
178
|
```
|
|
197
179
|
|
|
198
|
-
### Working with packaged components & libraries
|
|
180
|
+
### Working with packaged components & libraries
|
|
199
181
|
|
|
200
182
|
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.
|
|
201
183
|
|
|
202
184
|
```javascript
|
|
203
185
|
// version 1
|
|
204
186
|
entry: {
|
|
205
|
-
|
|
187
|
+
multiselect_v1: "./src/main.ts"
|
|
206
188
|
}
|
|
207
189
|
|
|
208
190
|
// version 2
|
|
209
191
|
entry: {
|
|
210
|
-
|
|
192
|
+
multiselect_v2: "./src/main.ts"
|
|
211
193
|
}
|
|
212
194
|
```
|
|
195
|
+
|
|
213
196
|
#### DLL
|
|
214
197
|
|
|
215
198
|
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:
|
|
199
|
+
|
|
216
200
|
```javascript
|
|
217
201
|
|
|
218
202
|
entry: {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
203
|
+
multiselect_v2: [
|
|
204
|
+
'@studyportals/multiselect/dist/multiselect.js',
|
|
205
|
+
'@studyportals/multiselect/dist/multiselect.css'
|
|
206
|
+
]
|
|
223
207
|
}
|
|
224
208
|
|
|
225
209
|
```
|
|
@@ -237,17 +221,17 @@ The output object has some options that define how your bundle will be output. I
|
|
|
237
221
|
|
|
238
222
|
```javascript
|
|
239
223
|
output: {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
224
|
+
path: path.resolve(__dirname, './dist'),
|
|
225
|
+
library: 'test-microservice',
|
|
226
|
+
publicPath: '/assets/',
|
|
227
|
+
fileName: 'application',
|
|
228
|
+
crossOriginLoading: 'anonymous',
|
|
229
|
+
hash: false,
|
|
230
|
+
//or
|
|
231
|
+
hash: {
|
|
232
|
+
js: true,
|
|
233
|
+
css: false
|
|
234
|
+
}
|
|
251
235
|
}
|
|
252
236
|
```
|
|
253
237
|
|
|
@@ -273,17 +257,17 @@ The bob object adds all necessary configuration to have your project generate a
|
|
|
273
257
|
|
|
274
258
|
```javascript
|
|
275
259
|
bob: {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
260
|
+
name: 'MicroService',
|
|
261
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
262
|
+
baseURL: '/dist',
|
|
263
|
+
defer: ['style'],
|
|
264
|
+
exclude: ['demo-assets'],
|
|
265
|
+
dllPackages: [
|
|
266
|
+
{
|
|
267
|
+
name: "package-dll",
|
|
268
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
269
|
+
}
|
|
270
|
+
]
|
|
287
271
|
}
|
|
288
272
|
```
|
|
289
273
|
|
|
@@ -293,6 +277,16 @@ WebpackHelper uses [BobManifestGenerator](https://github.com/studyportals/BobMan
|
|
|
293
277
|
|
|
294
278
|
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).
|
|
295
279
|
|
|
280
|
+
### staticPath **(required)**
|
|
281
|
+
|
|
282
|
+
Your configuration must include the following
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
staticPath: path.join(__dirname, "."),
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
No Extra configuration is needed for the webpack-dev-server
|
|
289
|
+
|
|
296
290
|
### development
|
|
297
291
|
|
|
298
292
|
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).
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studyportals/webpack-helper",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-3",
|
|
4
4
|
"description": "A collection of standard configurations and helpers for webpack.",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "vitest --watch=false --coverage",
|
|
8
8
|
"build": "tsc",
|
|
9
9
|
"prepublish": "npm run build",
|
|
10
|
-
"postinstall": "
|
|
10
|
+
"postinstall": "cp ./assets/.browserslistrc ../../../",
|
|
11
11
|
"deploy-beta": "npm version prerelease && npm run build && npm publish --tag beta --access=public --auth-type=legacy && rm -rf node_modules"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DevelopmentConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const process = require('process');
|
|
6
|
+
exports.DevelopmentConfig = {
|
|
5
7
|
optimization: {
|
|
6
8
|
minimize: false
|
|
7
9
|
},
|
|
@@ -19,7 +21,6 @@ const DevelopmentConfig = (staticPath) => ({
|
|
|
19
21
|
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
20
22
|
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
|
|
21
23
|
},
|
|
22
|
-
static:
|
|
24
|
+
static: path.join(process.cwd(), "."),
|
|
23
25
|
}
|
|
24
|
-
}
|
|
25
|
-
exports.DevelopmentConfig = DevelopmentConfig;
|
|
26
|
+
};
|
|
@@ -35,7 +35,7 @@ class Configuration {
|
|
|
35
35
|
const configDev = options[mode_1.Mode.DEVELOPMENT] ? options[mode_1.Mode.DEVELOPMENT] : {};
|
|
36
36
|
const configPrd = options[mode_1.Mode.PRODUCTION] ? options[mode_1.Mode.PRODUCTION] : {};
|
|
37
37
|
this.environmentSpecificConfig = {
|
|
38
|
-
[mode_1.Mode.DEVELOPMENT]: merge([configDev,
|
|
38
|
+
[mode_1.Mode.DEVELOPMENT]: merge([configDev, development_config_1.DevelopmentConfig]) || development_config_1.DevelopmentConfig,
|
|
39
39
|
[mode_1.Mode.PRODUCTION]: merge([configPrd, (0, production_config_1.ProductionConfig)(this.bob)]) || (0, production_config_1.ProductionConfig)(this.bob)
|
|
40
40
|
};
|
|
41
41
|
this.fileName = options.output.fileName || "[name]";
|