@studyportals/webpack-helper 7.0.0-2 → 7.0.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 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
- - [Configuration](#configuration)
12
+ - [Setup](#setup)
12
13
  - [Limitations](#limitations)
13
14
  - [Configuration](#configuration)
14
15
  - [entry](#entry-required)
@@ -22,51 +23,26 @@ WebpackHelper is a utility that makes it easy to set up a webpack configuration
22
23
  - [javascript](#javascript)
23
24
  - [typescript](#typescript)
24
25
  - [vue-typescript](#vue-typescript)
25
- - [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
26
+ - [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
26
27
 
27
28
  ## Webpack version
29
+
28
30
  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
31
 
30
32
  ### 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
33
 
33
- #### Dev server
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
- ```
34
+ 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
35
 
64
36
  #### Exporting
37
+
65
38
  Webpack-helper **v2 and below**: Your `webpack.config.js` file ended with the following:
39
+
66
40
  ```javascript
67
41
  module.exports = mode => configuration.get(mode);
68
42
  ```
43
+
69
44
  Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should end with the following (as is also mentioned further below):
45
+
70
46
  ```javascript
71
47
  module.exports = (env, details) => configuration.get(details.mode);
72
48
  ```
@@ -84,41 +60,38 @@ const path = require('path');
84
60
  const WebpackHelper = require("@studyportals/webpack-helper");
85
61
 
86
62
  const configuration = WebpackHelper.create({
87
- entry: [
88
- "./src/main.ts"
89
- ],
90
- output: {
91
- path: path.resolve(__dirname, './dist'),
92
- fileName: 'bundle',
93
- hash: true,
94
- // Use this if you want to control hashing for js and css separately
95
- hash: {
96
- js: true,
97
- css: false
98
- }
99
- },
100
- preset: "vue-typescript",
101
- bob: {
102
- name: 'MicroService',
103
- html: '<div id=\"MicroServicePlaceholder\"></div>',
104
- baseURL: '/dist',
105
- defer: ['style'],
106
- dllPackages: [
107
- {
108
- name: "package-dll",
109
- manifest: require("@studyportals/package-dll/dist/manifest.json")
110
- }
111
- ]
112
- },
113
- common: {
114
- //any config
115
- },
116
- development: {
117
- //any config
118
- },
119
- production: {
120
- //any config
121
- }
63
+ entry: [
64
+ "./src/main.ts"
65
+ ],
66
+ output: {
67
+ path: path.resolve(__dirname, './dist'),
68
+ fileName: 'bundle',
69
+ hash: true,
70
+ // Use this if you want to control hashing for js and css separately
71
+ hash: {
72
+ js: true,
73
+ css: false
74
+ }
75
+ },
76
+ preset: "vue-typescript",
77
+ bob: {
78
+ name: 'MicroService',
79
+ html: '<div id=\"MicroServicePlaceholder\"></div>',
80
+ baseURL: '/dist',
81
+ defer: ['style'],
82
+ dllPackages: [
83
+ {
84
+ name: "package-dll",
85
+ manifest: require("@studyportals/package-dll/dist/manifest.json")
86
+ }
87
+ ]
88
+ },
89
+ common: {
90
+ //any config
91
+ },
92
+ production: {
93
+ //any config
94
+ }
122
95
  });
123
96
  ```
124
97
 
@@ -129,29 +102,32 @@ module.exports = (env, details) => configuration.get(details.mode);
129
102
  ```
130
103
 
131
104
  ## Chunks Retry
105
+
132
106
  Webpack Helpers has a default configuration to retry chunks which cannot get loaded on the first try (for whatever reason, network or otherwise).
133
107
 
134
108
  It has an Exponential Backoff to calculate the delay between retries of a maximum of `2` seconds.
135
109
 
136
- The functionality is implemented thru a plugin called `webpack-retry-chunk-load-plugin` https://www.npmjs.com/package/webpack-retry-chunk-load-plugin.
110
+ The functionality is implemented thru a plugin called `webpack-retry-chunk-load-plugin` <https://www.npmjs.com/package/webpack-retry-chunk-load-plugin>.
137
111
 
138
112
  ### Defaults
139
113
 
140
114
  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
115
 
142
- ### Configuration
116
+ ### Setup
117
+
143
118
  To configure the functionality you can provide an object following this interface
119
+
144
120
  ```js
145
121
  interface IChunksRetryPluginConfig {
146
- inject: boolean; //if you want the plugin injected
122
+ inject: boolean; //if you want the plugin injected
147
123
 
148
- threshold: number; //amount of retries
124
+ threshold: number; //amount of retries
149
125
 
150
- thresholdReachedCallBack?: string; //a function (body of it as string) to be called when the amount of retries has been exhausted
126
+ thresholdReachedCallBack?: string; //a function (body of it as string) to be called when the amount of retries has been exhausted
151
127
 
152
- 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'
128
+ 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
129
 
154
- disableDefaultRollbarError?: boolean; //if you don't want to log by default when the threshold has been reached
130
+ disableDefaultRollbarError?: boolean; //if you don't want to log by default when the threshold has been reached
155
131
  }
156
132
  ```
157
133
 
@@ -159,20 +135,23 @@ and you can provide this thru the `webpack` config of your service like so
159
135
 
160
136
  ```js
161
137
  const configuration = WebpackHelper.create({
162
- chunksRetryConfig: {
163
- threshold: 10,
164
- thresholdReachedCallBack: `console.log("hello")`,
165
- },
166
- ...
138
+ chunksRetryConfig: {
139
+ threshold: 10,
140
+ thresholdReachedCallBack: `console.log("hello")`,
141
+ },
142
+ ...
167
143
  ```
168
144
 
169
145
  ### Limitations
146
+
170
147
  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
148
 
172
149
  ### Only use ES5
150
+
173
151
  You can only write ES5 code inside the `thresholdReachedCallBack`
174
152
 
175
153
  ### String as function
154
+
176
155
  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
156
 
178
157
  ## Configuration
@@ -185,41 +164,43 @@ The entrypoint for your webpack bundle. This can either be configured as an obje
185
164
 
186
165
  ```javascript
187
166
  entry: [
188
- "./src/main.ts"
167
+ "./src/main.ts"
189
168
  ]
190
169
 
191
170
  //or
192
171
 
193
172
  entry: {
194
- bundle: "./src/main.ts"
173
+ bundle: "./src/main.ts"
195
174
  }
196
175
  ```
197
176
 
198
- ### Working with packaged components & libraries
177
+ ### Working with packaged components & libraries
199
178
 
200
179
  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
180
 
202
181
  ```javascript
203
182
  // version 1
204
183
  entry: {
205
- multiselect_v1: "./src/main.ts"
184
+ multiselect_v1: "./src/main.ts"
206
185
  }
207
186
 
208
187
  // version 2
209
188
  entry: {
210
- multiselect_v2: "./src/main.ts"
189
+ multiselect_v2: "./src/main.ts"
211
190
  }
212
191
  ```
192
+
213
193
  #### DLL
214
194
 
215
195
  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:
196
+
216
197
  ```javascript
217
198
 
218
199
  entry: {
219
- multiselect_v2: [
220
- '@studyportals/multiselect/dist/multiselect.js',
221
- '@studyportals/multiselect/dist/multiselect.css'
222
- ]
200
+ multiselect_v2: [
201
+ '@studyportals/multiselect/dist/multiselect.js',
202
+ '@studyportals/multiselect/dist/multiselect.css'
203
+ ]
223
204
  }
224
205
 
225
206
  ```
@@ -237,17 +218,17 @@ The output object has some options that define how your bundle will be output. I
237
218
 
238
219
  ```javascript
239
220
  output: {
240
- path: path.resolve(__dirname, './dist'),
241
- library: 'test-microservice',
242
- publicPath: '/assets/',
243
- fileName: 'application',
244
- crossOriginLoading: 'anonymous',
245
- hash: false,
246
- //or
247
- hash: {
248
- js: true,
249
- css: false
250
- }
221
+ path: path.resolve(__dirname, './dist'),
222
+ library: 'test-microservice',
223
+ publicPath: '/assets/',
224
+ fileName: 'application',
225
+ crossOriginLoading: 'anonymous',
226
+ hash: false,
227
+ //or
228
+ hash: {
229
+ js: true,
230
+ css: false
231
+ }
251
232
  }
252
233
  ```
253
234
 
@@ -273,17 +254,17 @@ The bob object adds all necessary configuration to have your project generate a
273
254
 
274
255
  ```javascript
275
256
  bob: {
276
- name: 'MicroService',
277
- html: '<div id=\"MicroServicePlaceholder\"></div>',
278
- baseURL: '/dist',
279
- defer: ['style'],
280
- exclude: ['demo-assets'],
281
- dllPackages: [
282
- {
283
- name: "package-dll",
284
- manifest: require("@studyportals/package-dll/dist/manifest.json")
285
- }
286
- ]
257
+ name: 'MicroService',
258
+ html: '<div id=\"MicroServicePlaceholder\"></div>',
259
+ baseURL: '/dist',
260
+ defer: ['style'],
261
+ exclude: ['demo-assets'],
262
+ dllPackages: [
263
+ {
264
+ name: "package-dll",
265
+ manifest: require("@studyportals/package-dll/dist/manifest.json")
266
+ }
267
+ ]
287
268
  }
288
269
  ```
289
270
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@studyportals/webpack-helper",
3
- "version": "7.0.0-2",
3
+ "version": "7.0.0",
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": "sudo cp ./assets/.browserslistrc ../../../",
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 DevelopmentConfig = (staticPath) => ({
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: staticPath
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, (0, development_config_1.DevelopmentConfig)(options.staticPath)]) || (0, development_config_1.DevelopmentConfig)(options.staticPath),
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]";