@studyportals/webpack-helper 6.0.4 → 6.0.5-1
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 +283 -283
- package/assets/.browserslistrc +2 -2
- package/package.json +49 -49
- package/src/enums/preset.js +0 -1
- package/src/model/configuration.js +0 -4
- package/src/presets/javascript.preset.js +6 -1
- package/src/presets/typescript.preset.js +6 -1
- package/src/presets/vue-typescript.preset.js +6 -1
- package/src/presets/vue-typescript-no-code-splitting.preset.js +0 -20
package/README.md
CHANGED
|
@@ -1,283 +1,283 @@
|
|
|
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
|
-
- [Webpack version](#webpack-version)
|
|
7
|
-
- [Notes on updating Webpack from v4 to v5](#notes-on-updating-webpack-from-v4-to-v5)
|
|
8
|
-
- [Quick Start](#quick-start)
|
|
9
|
-
- [Configuration](#configuration)
|
|
10
|
-
- [entry](#entry-required)
|
|
11
|
-
- [output](#output-required)
|
|
12
|
-
- [preset](#preset)
|
|
13
|
-
- [bob](#bob)
|
|
14
|
-
- [common](#common)
|
|
15
|
-
- [development](#development)
|
|
16
|
-
- [production](#production)
|
|
17
|
-
- [Presets](#presets)
|
|
18
|
-
- [javascript](#javascript)
|
|
19
|
-
- [typescript](#typescript)
|
|
20
|
-
- [vue-typescript](#vue-typescript)
|
|
21
|
-
- [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
|
|
22
|
-
|
|
23
|
-
## Webpack version
|
|
24
|
-
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/).
|
|
25
|
-
|
|
26
|
-
### Notes on updating Webpack from v4 to v5
|
|
27
|
-
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).
|
|
28
|
-
|
|
29
|
-
#### Dev server
|
|
30
|
-
Webpack-helper **v2 and below**: Your `development.devServer` file might include these parts:
|
|
31
|
-
```javascript
|
|
32
|
-
{
|
|
33
|
-
development: {
|
|
34
|
-
devServer: {
|
|
35
|
-
open: true,
|
|
36
|
-
overlay: true,
|
|
37
|
-
writeToDisk: true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should configure those parts like this:
|
|
43
|
-
```javascript
|
|
44
|
-
{
|
|
45
|
-
development: {
|
|
46
|
-
devServer: {
|
|
47
|
-
client: {
|
|
48
|
-
overlay: true
|
|
49
|
-
},
|
|
50
|
-
devMiddleware: {
|
|
51
|
-
writeToDisk: true
|
|
52
|
-
},
|
|
53
|
-
open: true,
|
|
54
|
-
static: path.join(__dirname, '.') // Related to writeToDisk.
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### Exporting
|
|
61
|
-
Webpack-helper **v2 and below**: Your `webpack.config.js` file ended with the following:
|
|
62
|
-
```javascript
|
|
63
|
-
module.exports = mode => configuration.get(mode);
|
|
64
|
-
```
|
|
65
|
-
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should end with the following (as is also mentioned further below):
|
|
66
|
-
```javascript
|
|
67
|
-
module.exports = (env, details) => configuration.get(details.mode);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Quick Start
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
npm i -D @studyportals/webpack-helper
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
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:
|
|
77
|
-
|
|
78
|
-
```javascript
|
|
79
|
-
const path = require('path');
|
|
80
|
-
const WebpackHelper = require("@studyportals/webpack-helper");
|
|
81
|
-
|
|
82
|
-
const configuration = WebpackHelper.create({
|
|
83
|
-
entry: [
|
|
84
|
-
"./src/main.ts"
|
|
85
|
-
],
|
|
86
|
-
output: {
|
|
87
|
-
path: path.resolve(__dirname, './dist'),
|
|
88
|
-
fileName: 'bundle',
|
|
89
|
-
hash: true,
|
|
90
|
-
// Use this if you want to control hashing for js and css separately
|
|
91
|
-
hash: {
|
|
92
|
-
js: true,
|
|
93
|
-
css: false
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
preset: "vue-typescript",
|
|
97
|
-
bob: {
|
|
98
|
-
name: 'MicroService',
|
|
99
|
-
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
100
|
-
baseURL: '/dist',
|
|
101
|
-
defer: ['style'],
|
|
102
|
-
dllPackages: [
|
|
103
|
-
{
|
|
104
|
-
name: "package-dll",
|
|
105
|
-
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
106
|
-
}
|
|
107
|
-
]
|
|
108
|
-
},
|
|
109
|
-
common: {
|
|
110
|
-
//any config
|
|
111
|
-
},
|
|
112
|
-
development: {
|
|
113
|
-
//any config
|
|
114
|
-
},
|
|
115
|
-
production: {
|
|
116
|
-
//any config
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
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:
|
|
122
|
-
|
|
123
|
-
```javascript
|
|
124
|
-
module.exports = (env, details) => configuration.get(details.mode);
|
|
125
|
-
```
|
|
126
|
-
## Configuration
|
|
127
|
-
|
|
128
|
-
Webpack Helper offers a compact but flexible configuration interface. Below you will find every option available.
|
|
129
|
-
|
|
130
|
-
### entry **(required)**
|
|
131
|
-
|
|
132
|
-
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.
|
|
133
|
-
|
|
134
|
-
```javascript
|
|
135
|
-
entry: [
|
|
136
|
-
"./src/main.ts"
|
|
137
|
-
]
|
|
138
|
-
|
|
139
|
-
//or
|
|
140
|
-
|
|
141
|
-
entry: {
|
|
142
|
-
bundle: "./src/main.ts"
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### Working with packaged components & libraries
|
|
147
|
-
|
|
148
|
-
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.
|
|
149
|
-
|
|
150
|
-
```javascript
|
|
151
|
-
// version 1
|
|
152
|
-
entry: {
|
|
153
|
-
multiselect_v1: "./src/main.ts"
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// version 2
|
|
157
|
-
entry: {
|
|
158
|
-
multiselect_v2: "./src/main.ts"
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
#### DLL
|
|
162
|
-
|
|
163
|
-
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:
|
|
164
|
-
```javascript
|
|
165
|
-
|
|
166
|
-
entry: {
|
|
167
|
-
multiselect_v2: [
|
|
168
|
-
'@studyportals/multiselect/dist/multiselect.js',
|
|
169
|
-
'@studyportals/multiselect/dist/multiselect.css'
|
|
170
|
-
]
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### output **(required)**
|
|
176
|
-
|
|
177
|
-
The output object has some options that define how your bundle will be output. It has the following properties:
|
|
178
|
-
|
|
179
|
-
- `path`**(required)**: The target directory for all output files.
|
|
180
|
-
- `library`: The name of the exported library, which will also be used to namespace sourcemaps. This will default to `null`.
|
|
181
|
-
- `publicPath`: The url to the output directory resolved relative to the HTML page. This will default to `null`.
|
|
182
|
-
- `fileName`: A custom filename for your bundle. This will default to `[name]` which refers to the name you've given your entrypoint.
|
|
183
|
-
- `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.
|
|
184
|
-
- `crossOriginLoading`: Tells webpack to enable cross-origin loading of chunks. Can either be set to `anonymous` or `user-credentials`.
|
|
185
|
-
|
|
186
|
-
```javascript
|
|
187
|
-
output: {
|
|
188
|
-
path: path.resolve(__dirname, './dist'),
|
|
189
|
-
library: 'test-microservice',
|
|
190
|
-
publicPath: '/assets/',
|
|
191
|
-
fileName: 'application',
|
|
192
|
-
crossOriginLoading: 'anonymous',
|
|
193
|
-
hash: false,
|
|
194
|
-
//or
|
|
195
|
-
hash: {
|
|
196
|
-
js: true,
|
|
197
|
-
css: false
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### preset
|
|
203
|
-
|
|
204
|
-
The preset property determines which preset to load into your webpack configuration.
|
|
205
|
-
|
|
206
|
-
```javascript
|
|
207
|
-
preset: "vue-typescript | typescript | javascript"
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### bob
|
|
211
|
-
|
|
212
|
-
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).
|
|
213
|
-
|
|
214
|
-
- `name`**(required)**: The name of your microservice.
|
|
215
|
-
- `html`**(required)**: The HTML that needs to be output by your microservice. Can be a path to a document or a snippet.
|
|
216
|
-
- `baseURL`: The baseURL for your microservice assets.
|
|
217
|
-
- `async`: An array of JS filenames to be loaded async.
|
|
218
|
-
- `defer`: An array of CSS filenames to be lazy-loaded.
|
|
219
|
-
- `exclude`: An array of filenames (CSS and JS) that should be excluded from your manifest file.
|
|
220
|
-
- `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.
|
|
221
|
-
|
|
222
|
-
```javascript
|
|
223
|
-
bob: {
|
|
224
|
-
name: 'MicroService',
|
|
225
|
-
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
226
|
-
baseURL: '/dist',
|
|
227
|
-
defer: ['style'],
|
|
228
|
-
exclude: ['demo-assets'],
|
|
229
|
-
dllPackages: [
|
|
230
|
-
{
|
|
231
|
-
name: "package-dll",
|
|
232
|
-
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
233
|
-
}
|
|
234
|
-
]
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
WebpackHelper uses [BobManifestGenerator](https://github.com/studyportals/BobManifestGenerator) to generate a manifest file.
|
|
239
|
-
|
|
240
|
-
### common
|
|
241
|
-
|
|
242
|
-
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).
|
|
243
|
-
|
|
244
|
-
### development
|
|
245
|
-
|
|
246
|
-
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).
|
|
247
|
-
|
|
248
|
-
**NOTE**: Some default configuration for development builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
249
|
-
|
|
250
|
-
### production
|
|
251
|
-
|
|
252
|
-
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).
|
|
253
|
-
|
|
254
|
-
**NOTE**: Some default configuration for production builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
255
|
-
|
|
256
|
-
## Presets
|
|
257
|
-
|
|
258
|
-
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.
|
|
259
|
-
|
|
260
|
-
More in depth information on what configuration these presets will add to your project can be found [here](src/presets/presets.md).
|
|
261
|
-
|
|
262
|
-
### javascript
|
|
263
|
-
|
|
264
|
-
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.
|
|
265
|
-
|
|
266
|
-
### typescript
|
|
267
|
-
|
|
268
|
-
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.
|
|
269
|
-
|
|
270
|
-
### vue-typescript
|
|
271
|
-
|
|
272
|
-
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.
|
|
273
|
-
|
|
274
|
-
## DoD compliance with Babel and Browserslist
|
|
275
|
-
|
|
276
|
-
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:
|
|
277
|
-
|
|
278
|
-
- `.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.
|
|
279
|
-
- `.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.
|
|
280
|
-
|
|
281
|
-
## Unit testing
|
|
282
|
-
|
|
283
|
-
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)
|
|
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
|
+
- [Webpack version](#webpack-version)
|
|
7
|
+
- [Notes on updating Webpack from v4 to v5](#notes-on-updating-webpack-from-v4-to-v5)
|
|
8
|
+
- [Quick Start](#quick-start)
|
|
9
|
+
- [Configuration](#configuration)
|
|
10
|
+
- [entry](#entry-required)
|
|
11
|
+
- [output](#output-required)
|
|
12
|
+
- [preset](#preset)
|
|
13
|
+
- [bob](#bob)
|
|
14
|
+
- [common](#common)
|
|
15
|
+
- [development](#development)
|
|
16
|
+
- [production](#production)
|
|
17
|
+
- [Presets](#presets)
|
|
18
|
+
- [javascript](#javascript)
|
|
19
|
+
- [typescript](#typescript)
|
|
20
|
+
- [vue-typescript](#vue-typescript)
|
|
21
|
+
- [DoD compliance with Babel and Browserslist](#dod-compliance-with-babel-and-browserslist)
|
|
22
|
+
|
|
23
|
+
## Webpack version
|
|
24
|
+
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/).
|
|
25
|
+
|
|
26
|
+
### Notes on updating Webpack from v4 to v5
|
|
27
|
+
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).
|
|
28
|
+
|
|
29
|
+
#### Dev server
|
|
30
|
+
Webpack-helper **v2 and below**: Your `development.devServer` file might include these parts:
|
|
31
|
+
```javascript
|
|
32
|
+
{
|
|
33
|
+
development: {
|
|
34
|
+
devServer: {
|
|
35
|
+
open: true,
|
|
36
|
+
overlay: true,
|
|
37
|
+
writeToDisk: true
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should configure those parts like this:
|
|
43
|
+
```javascript
|
|
44
|
+
{
|
|
45
|
+
development: {
|
|
46
|
+
devServer: {
|
|
47
|
+
client: {
|
|
48
|
+
overlay: true
|
|
49
|
+
},
|
|
50
|
+
devMiddleware: {
|
|
51
|
+
writeToDisk: true
|
|
52
|
+
},
|
|
53
|
+
open: true,
|
|
54
|
+
static: path.join(__dirname, '.') // Related to writeToDisk.
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Exporting
|
|
61
|
+
Webpack-helper **v2 and below**: Your `webpack.config.js` file ended with the following:
|
|
62
|
+
```javascript
|
|
63
|
+
module.exports = mode => configuration.get(mode);
|
|
64
|
+
```
|
|
65
|
+
Webpack-helper **v3 and beyond**: Your `webpack.config.js` file should end with the following (as is also mentioned further below):
|
|
66
|
+
```javascript
|
|
67
|
+
module.exports = (env, details) => configuration.get(details.mode);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm i -D @studyportals/webpack-helper
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
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:
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const path = require('path');
|
|
80
|
+
const WebpackHelper = require("@studyportals/webpack-helper");
|
|
81
|
+
|
|
82
|
+
const configuration = WebpackHelper.create({
|
|
83
|
+
entry: [
|
|
84
|
+
"./src/main.ts"
|
|
85
|
+
],
|
|
86
|
+
output: {
|
|
87
|
+
path: path.resolve(__dirname, './dist'),
|
|
88
|
+
fileName: 'bundle',
|
|
89
|
+
hash: true,
|
|
90
|
+
// Use this if you want to control hashing for js and css separately
|
|
91
|
+
hash: {
|
|
92
|
+
js: true,
|
|
93
|
+
css: false
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
preset: "vue-typescript",
|
|
97
|
+
bob: {
|
|
98
|
+
name: 'MicroService',
|
|
99
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
100
|
+
baseURL: '/dist',
|
|
101
|
+
defer: ['style'],
|
|
102
|
+
dllPackages: [
|
|
103
|
+
{
|
|
104
|
+
name: "package-dll",
|
|
105
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
common: {
|
|
110
|
+
//any config
|
|
111
|
+
},
|
|
112
|
+
development: {
|
|
113
|
+
//any config
|
|
114
|
+
},
|
|
115
|
+
production: {
|
|
116
|
+
//any config
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
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:
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
module.exports = (env, details) => configuration.get(details.mode);
|
|
125
|
+
```
|
|
126
|
+
## Configuration
|
|
127
|
+
|
|
128
|
+
Webpack Helper offers a compact but flexible configuration interface. Below you will find every option available.
|
|
129
|
+
|
|
130
|
+
### entry **(required)**
|
|
131
|
+
|
|
132
|
+
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.
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
entry: [
|
|
136
|
+
"./src/main.ts"
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
//or
|
|
140
|
+
|
|
141
|
+
entry: {
|
|
142
|
+
bundle: "./src/main.ts"
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Working with packaged components & libraries
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// version 1
|
|
152
|
+
entry: {
|
|
153
|
+
multiselect_v1: "./src/main.ts"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// version 2
|
|
157
|
+
entry: {
|
|
158
|
+
multiselect_v2: "./src/main.ts"
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
#### DLL
|
|
162
|
+
|
|
163
|
+
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:
|
|
164
|
+
```javascript
|
|
165
|
+
|
|
166
|
+
entry: {
|
|
167
|
+
multiselect_v2: [
|
|
168
|
+
'@studyportals/multiselect/dist/multiselect.js',
|
|
169
|
+
'@studyportals/multiselect/dist/multiselect.css'
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### output **(required)**
|
|
176
|
+
|
|
177
|
+
The output object has some options that define how your bundle will be output. It has the following properties:
|
|
178
|
+
|
|
179
|
+
- `path`**(required)**: The target directory for all output files.
|
|
180
|
+
- `library`: The name of the exported library, which will also be used to namespace sourcemaps. This will default to `null`.
|
|
181
|
+
- `publicPath`: The url to the output directory resolved relative to the HTML page. This will default to `null`.
|
|
182
|
+
- `fileName`: A custom filename for your bundle. This will default to `[name]` which refers to the name you've given your entrypoint.
|
|
183
|
+
- `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.
|
|
184
|
+
- `crossOriginLoading`: Tells webpack to enable cross-origin loading of chunks. Can either be set to `anonymous` or `user-credentials`.
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
output: {
|
|
188
|
+
path: path.resolve(__dirname, './dist'),
|
|
189
|
+
library: 'test-microservice',
|
|
190
|
+
publicPath: '/assets/',
|
|
191
|
+
fileName: 'application',
|
|
192
|
+
crossOriginLoading: 'anonymous',
|
|
193
|
+
hash: false,
|
|
194
|
+
//or
|
|
195
|
+
hash: {
|
|
196
|
+
js: true,
|
|
197
|
+
css: false
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### preset
|
|
203
|
+
|
|
204
|
+
The preset property determines which preset to load into your webpack configuration.
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
preset: "vue-typescript | typescript | javascript"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### bob
|
|
211
|
+
|
|
212
|
+
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).
|
|
213
|
+
|
|
214
|
+
- `name`**(required)**: The name of your microservice.
|
|
215
|
+
- `html`**(required)**: The HTML that needs to be output by your microservice. Can be a path to a document or a snippet.
|
|
216
|
+
- `baseURL`: The baseURL for your microservice assets.
|
|
217
|
+
- `async`: An array of JS filenames to be loaded async.
|
|
218
|
+
- `defer`: An array of CSS filenames to be lazy-loaded.
|
|
219
|
+
- `exclude`: An array of filenames (CSS and JS) that should be excluded from your manifest file.
|
|
220
|
+
- `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.
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
bob: {
|
|
224
|
+
name: 'MicroService',
|
|
225
|
+
html: '<div id=\"MicroServicePlaceholder\"></div>',
|
|
226
|
+
baseURL: '/dist',
|
|
227
|
+
defer: ['style'],
|
|
228
|
+
exclude: ['demo-assets'],
|
|
229
|
+
dllPackages: [
|
|
230
|
+
{
|
|
231
|
+
name: "package-dll",
|
|
232
|
+
manifest: require("@studyportals/package-dll/dist/manifest.json")
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
WebpackHelper uses [BobManifestGenerator](https://github.com/studyportals/BobManifestGenerator) to generate a manifest file.
|
|
239
|
+
|
|
240
|
+
### common
|
|
241
|
+
|
|
242
|
+
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).
|
|
243
|
+
|
|
244
|
+
### development
|
|
245
|
+
|
|
246
|
+
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).
|
|
247
|
+
|
|
248
|
+
**NOTE**: Some default configuration for development builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
249
|
+
|
|
250
|
+
### production
|
|
251
|
+
|
|
252
|
+
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).
|
|
253
|
+
|
|
254
|
+
**NOTE**: Some default configuration for production builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
255
|
+
|
|
256
|
+
## Presets
|
|
257
|
+
|
|
258
|
+
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.
|
|
259
|
+
|
|
260
|
+
More in depth information on what configuration these presets will add to your project can be found [here](src/presets/presets.md).
|
|
261
|
+
|
|
262
|
+
### javascript
|
|
263
|
+
|
|
264
|
+
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.
|
|
265
|
+
|
|
266
|
+
### typescript
|
|
267
|
+
|
|
268
|
+
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.
|
|
269
|
+
|
|
270
|
+
### vue-typescript
|
|
271
|
+
|
|
272
|
+
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.
|
|
273
|
+
|
|
274
|
+
## DoD compliance with Babel and Browserslist
|
|
275
|
+
|
|
276
|
+
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:
|
|
277
|
+
|
|
278
|
+
- `.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.
|
|
279
|
+
- `.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.
|
|
280
|
+
|
|
281
|
+
## Unit testing
|
|
282
|
+
|
|
283
|
+
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)
|
package/assets/.browserslistrc
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#extends @studyportals/browserslist-config/clients
|
|
2
|
-
#extends @studyportals/browserslist-config/internal
|
|
1
|
+
#extends @studyportals/browserslist-config/clients
|
|
2
|
+
#extends @studyportals/browserslist-config/internal
|
|
3
3
|
extends @studyportals/browserslist-config/student
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@studyportals/webpack-helper",
|
|
3
|
-
"version": "6.0.
|
|
4
|
-
"description": "A collection of standard configurations and helpers for webpack.",
|
|
5
|
-
"main": "src/main.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "vitest --watch=false --coverage",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"prepublish": "npm run build",
|
|
10
|
-
"postinstall": "cp ./assets/.browserslistrc ../../../",
|
|
11
|
-
"deploy-beta": "npm version prerelease && npm run build && npm publish --tag beta --access=public && rm -rf node_modules"
|
|
12
|
-
},
|
|
13
|
-
"files": [
|
|
14
|
-
"src/**/*.js",
|
|
15
|
-
"assets/*"
|
|
16
|
-
],
|
|
17
|
-
"author": {
|
|
18
|
-
"name": "Frank Kluijtmans",
|
|
19
|
-
"email": "frank@studyportals.com"
|
|
20
|
-
},
|
|
21
|
-
"license": "ISC",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@studyportals/bob-manifest-generator": "^5.0.1",
|
|
24
|
-
"@studyportals/browserslist-config": "^1.2.4",
|
|
25
|
-
"@studyportals/dll-availability-tracker": "^2.0.0",
|
|
26
|
-
"@studyportals/vue-config": "^5.0.2",
|
|
27
|
-
"css-loader": "^6.10.0",
|
|
28
|
-
"css-minimizer-webpack-plugin": "^6.0.0",
|
|
29
|
-
"esbuild-loader": "^4.0.3",
|
|
30
|
-
"esbuild-plugin-browserslist": "^0.11.1",
|
|
31
|
-
"file-loader": "^6.2.0",
|
|
32
|
-
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
33
|
-
"mini-css-extract-plugin": "^2.8.0",
|
|
34
|
-
"path": "^0.12.7",
|
|
35
|
-
"sass": "^1.71.1",
|
|
36
|
-
"sass-loader": "^14.1.1",
|
|
37
|
-
"terser-webpack-plugin": "^5.3.10",
|
|
38
|
-
"typescript": "^5.3.3",
|
|
39
|
-
"vue-loader": "^17.4.2",
|
|
40
|
-
"webpack": "^5.90.3",
|
|
41
|
-
"webpack-cli": "^5.1.4",
|
|
42
|
-
"webpack-merge": "^5.10.0"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"@types/node": "^20.11.20",
|
|
46
|
-
"@vitest/coverage-v8": "^1.3.1",
|
|
47
|
-
"vitest": "^1.3.1"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@studyportals/webpack-helper",
|
|
3
|
+
"version": "6.0.5-1",
|
|
4
|
+
"description": "A collection of standard configurations and helpers for webpack.",
|
|
5
|
+
"main": "src/main.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "vitest --watch=false --coverage",
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublish": "npm run build",
|
|
10
|
+
"postinstall": "cp ./assets/.browserslistrc ../../../",
|
|
11
|
+
"deploy-beta": "npm version prerelease && npm run build && npm publish --tag beta --access=public && rm -rf node_modules"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src/**/*.js",
|
|
15
|
+
"assets/*"
|
|
16
|
+
],
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Frank Kluijtmans",
|
|
19
|
+
"email": "frank@studyportals.com"
|
|
20
|
+
},
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@studyportals/bob-manifest-generator": "^5.0.1",
|
|
24
|
+
"@studyportals/browserslist-config": "^1.2.4",
|
|
25
|
+
"@studyportals/dll-availability-tracker": "^2.0.0",
|
|
26
|
+
"@studyportals/vue-config": "^5.0.2",
|
|
27
|
+
"css-loader": "^6.10.0",
|
|
28
|
+
"css-minimizer-webpack-plugin": "^6.0.0",
|
|
29
|
+
"esbuild-loader": "^4.0.3",
|
|
30
|
+
"esbuild-plugin-browserslist": "^0.11.1",
|
|
31
|
+
"file-loader": "^6.2.0",
|
|
32
|
+
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
33
|
+
"mini-css-extract-plugin": "^2.8.0",
|
|
34
|
+
"path": "^0.12.7",
|
|
35
|
+
"sass": "^1.71.1",
|
|
36
|
+
"sass-loader": "^14.1.1",
|
|
37
|
+
"terser-webpack-plugin": "^5.3.10",
|
|
38
|
+
"typescript": "^5.3.3",
|
|
39
|
+
"vue-loader": "^17.4.2",
|
|
40
|
+
"webpack": "^5.90.3",
|
|
41
|
+
"webpack-cli": "^5.1.4",
|
|
42
|
+
"webpack-merge": "^5.10.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^20.11.20",
|
|
46
|
+
"@vitest/coverage-v8": "^1.3.1",
|
|
47
|
+
"vitest": "^1.3.1"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/enums/preset.js
CHANGED
|
@@ -9,7 +9,6 @@ const preset_1 = require("../enums/preset");
|
|
|
9
9
|
const vue_typescript_preset_1 = require("../presets/vue-typescript.preset");
|
|
10
10
|
const typescript_preset_1 = require("../presets/typescript.preset");
|
|
11
11
|
const javascript_preset_1 = require("../presets/javascript.preset");
|
|
12
|
-
const vue_typescript_no_code_splitting_preset_1 = require("../presets/vue-typescript-no-code-splitting.preset");
|
|
13
12
|
const mode_1 = require("../enums/mode");
|
|
14
13
|
const production_config_1 = require("../defaults/production.config");
|
|
15
14
|
const development_config_1 = require("../defaults/development.config");
|
|
@@ -66,9 +65,6 @@ class Configuration {
|
|
|
66
65
|
case preset_1.Preset.JAVASCRIPT:
|
|
67
66
|
this.injectPreset(new javascript_preset_1.JavascriptPreset());
|
|
68
67
|
break;
|
|
69
|
-
case preset_1.Preset.VUE_TYPESCRIPT_NO_CODE_SPLITTING:
|
|
70
|
-
this.injectPreset(new vue_typescript_no_code_splitting_preset_1.VueTypescriptNoCodeSplittingPreset(mode, this.customElementTags));
|
|
71
|
-
break;
|
|
72
68
|
default:
|
|
73
69
|
break;
|
|
74
70
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VueTypescriptNoCodeSplittingPreset = void 0;
|
|
4
|
-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
|
5
|
-
const VueLoaderPlugin = require('vue-loader').VueLoaderPlugin;
|
|
6
|
-
const vue_typescript_preset_1 = require("./vue-typescript.preset");
|
|
7
|
-
class VueTypescriptNoCodeSplittingPreset extends vue_typescript_preset_1.VueTypeScriptPreset {
|
|
8
|
-
constructor(mode, customElementTags) {
|
|
9
|
-
super(mode, customElementTags);
|
|
10
|
-
}
|
|
11
|
-
getPlugins(filename) {
|
|
12
|
-
return [
|
|
13
|
-
new MiniCssExtractPlugin({
|
|
14
|
-
filename
|
|
15
|
-
}),
|
|
16
|
-
new VueLoaderPlugin()
|
|
17
|
-
];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.VueTypescriptNoCodeSplittingPreset = VueTypescriptNoCodeSplittingPreset;
|