@studyportals/webpack-helper 8.0.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 +15 -0
- package/dist/defaults/production.config.js +79 -0
- package/{src → dist}/factories/chunks-retry-plugin-factory.js +2 -4
- package/dist/interfaces/preset.interface.js +2 -0
- package/{src → dist}/model/configuration.js +2 -1
- package/dist/utils/cpus.js +29 -0
- package/package.json +12 -8
- 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}/plugins/retry-chunk-load.plugin.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
|
@@ -23,6 +23,7 @@ WebpackHelper is a utility that makes it easy to set up a webpack configuration
|
|
|
23
23
|
- [common](#common)
|
|
24
24
|
- [development](#development)
|
|
25
25
|
- [production](#production)
|
|
26
|
+
- [minify](#minify)
|
|
26
27
|
- [Presets](#presets)
|
|
27
28
|
- [javascript](#javascript)
|
|
28
29
|
- [typescript](#typescript)
|
|
@@ -359,6 +360,20 @@ Extra Webpack configuration to be used for all production builds can be passed i
|
|
|
359
360
|
|
|
360
361
|
**NOTE**: Some default configuration for production builds will be added automatically. Details can be found [here](src/defaults/defaults.md).
|
|
361
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
|
+
|
|
362
377
|
## Presets
|
|
363
378
|
|
|
364
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductionConfig = void 0;
|
|
4
|
+
const cpus_1 = require("../utils/cpus");
|
|
5
|
+
const browser_list_to_esbuild_target_factory_1 = require("../factories/browser-list-to-esbuild-target-factory");
|
|
6
|
+
const webpack = require('webpack');
|
|
7
|
+
const cssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
8
|
+
const DllAvailabilityTracker = require('@studyportals/dll-availability-tracker');
|
|
9
|
+
const DEFAULT_TERSER_PASSES = 2;
|
|
10
|
+
const ProductionConfig = (bobConfig, minifyConfig = {}) => {
|
|
11
|
+
let dllDependencies = ['library'];
|
|
12
|
+
if (bobConfig && bobConfig.hasOwnProperty('dllPackages')) {
|
|
13
|
+
bobConfig.dllPackages.forEach((dependency) => dllDependencies.push(dependency.manifest.name));
|
|
14
|
+
}
|
|
15
|
+
const parallel = (0, cpus_1.getAvailableCpus)();
|
|
16
|
+
return {
|
|
17
|
+
plugins: [
|
|
18
|
+
new webpack.DefinePlugin({
|
|
19
|
+
'process.env': {
|
|
20
|
+
NODE_ENV: '"production"'
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
minifyConfig.css !== 'lightningcss'
|
|
24
|
+
? new cssMinimizerPlugin({
|
|
25
|
+
parallel,
|
|
26
|
+
minimizerOptions: {
|
|
27
|
+
preset: [
|
|
28
|
+
'default',
|
|
29
|
+
{
|
|
30
|
+
discardComments: {
|
|
31
|
+
removeAll: true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
: new cssMinimizerPlugin({
|
|
38
|
+
parallel,
|
|
39
|
+
minify: cssMinimizerPlugin.lightningCssMinify
|
|
40
|
+
}),
|
|
41
|
+
new DllAvailabilityTracker({
|
|
42
|
+
dependencies: dllDependencies || []
|
|
43
|
+
})
|
|
44
|
+
],
|
|
45
|
+
optimization: {
|
|
46
|
+
minimize: true,
|
|
47
|
+
minimizer: [
|
|
48
|
+
compiler => {
|
|
49
|
+
console.log(`webpack-helper: minifying JS with ${minifyConfig.minifier || 'terser'}, CSS with ${minifyConfig.css || 'cssnano'}, on ${parallel} CPU(s)`);
|
|
50
|
+
if (minifyConfig.minifier === 'esbuild') {
|
|
51
|
+
const { EsbuildPlugin } = require('esbuild-loader');
|
|
52
|
+
new EsbuildPlugin({
|
|
53
|
+
target: new browser_list_to_esbuild_target_factory_1.BrowserListToEsbuildTargetFactory().createTarget(),
|
|
54
|
+
drop: ['console'],
|
|
55
|
+
legalComments: 'none'
|
|
56
|
+
}).apply(compiler);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const TerserPlugin = require('terser-webpack-plugin');
|
|
60
|
+
new TerserPlugin({
|
|
61
|
+
parallel,
|
|
62
|
+
extractComments: false,
|
|
63
|
+
terserOptions: {
|
|
64
|
+
output: {
|
|
65
|
+
comments: false
|
|
66
|
+
},
|
|
67
|
+
compress: {
|
|
68
|
+
drop_console: true,
|
|
69
|
+
passes: minifyConfig.passes || DEFAULT_TERSER_PASSES
|
|
70
|
+
},
|
|
71
|
+
sourceMap: true
|
|
72
|
+
}
|
|
73
|
+
}).apply(compiler);
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
exports.ProductionConfig = ProductionConfig;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const mode_1 = require("../enums/mode");
|
|
4
|
-
const
|
|
5
|
-
const process = require('process');
|
|
6
|
-
const { RetryChunkLoadPlugin } = require(path.join(process.cwd(), 'node_modules', '@studyportals/webpack-helper', 'src', 'plugins', 'retry-chunk-load.plugin.js'));
|
|
4
|
+
const retry_chunk_load_plugin_1 = require("../plugins/retry-chunk-load.plugin");
|
|
7
5
|
class ChunksRetryPluginFactory {
|
|
8
6
|
static IsPresetSupported(preset) {
|
|
9
7
|
if (!preset.retryChunksConfig)
|
|
@@ -19,7 +17,7 @@ class ChunksRetryPluginFactory {
|
|
|
19
17
|
}
|
|
20
18
|
static CustomRetryChunksPlugin(preset) {
|
|
21
19
|
const { retryChunksConfig } = preset;
|
|
22
|
-
return new RetryChunkLoadPlugin({
|
|
20
|
+
return new retry_chunk_load_plugin_1.RetryChunkLoadPlugin({
|
|
23
21
|
cacheBust: `function() {
|
|
24
22
|
return Date.now();
|
|
25
23
|
}`,
|
|
@@ -23,6 +23,7 @@ const DEFAULT_CHUNKS_RETRY_CONFIG_THRESHOLD = 6;
|
|
|
23
23
|
class Configuration {
|
|
24
24
|
constructor(options) {
|
|
25
25
|
this.customElementTags = options.customElementTags || [];
|
|
26
|
+
this.minifyConfig = options.minify || {};
|
|
26
27
|
this.bob = options.bob || null;
|
|
27
28
|
this.entry = new entry_1.Entry(options.entry);
|
|
28
29
|
this.output = new output_1.Output(options.output);
|
|
@@ -36,7 +37,7 @@ class Configuration {
|
|
|
36
37
|
const configPrd = options[mode_1.Mode.PRODUCTION] ? options[mode_1.Mode.PRODUCTION] : {};
|
|
37
38
|
this.environmentSpecificConfig = {
|
|
38
39
|
[mode_1.Mode.DEVELOPMENT]: merge([configDev, development_config_1.DevelopmentConfig]) || development_config_1.DevelopmentConfig,
|
|
39
|
-
[mode_1.Mode.PRODUCTION]: merge([configPrd, (0, production_config_1.ProductionConfig)(this.bob)]) || (0, production_config_1.ProductionConfig)(this.bob)
|
|
40
|
+
[mode_1.Mode.PRODUCTION]: merge([configPrd, (0, production_config_1.ProductionConfig)(this.bob, this.minifyConfig)]) || (0, production_config_1.ProductionConfig)(this.bob, this.minifyConfig)
|
|
40
41
|
};
|
|
41
42
|
this.fileName = options.output.fileName || "[name]";
|
|
42
43
|
this.chunksRetryConfig = options.chunksRetryConfig || {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAvailableCpus = void 0;
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const getCgroupCpuLimit = () => {
|
|
7
|
+
try {
|
|
8
|
+
const [quota, period] = fs.readFileSync('/sys/fs/cgroup/cpu.max', 'utf8').trim().split(/\s+/);
|
|
9
|
+
return quota === 'max' ? null : Math.max(1, Math.floor(Number(quota) / Number(period)));
|
|
10
|
+
}
|
|
11
|
+
catch (e) { }
|
|
12
|
+
try {
|
|
13
|
+
const quota = Number(fs.readFileSync('/sys/fs/cgroup/cpu/cpu.cfs_quota_us', 'utf8'));
|
|
14
|
+
const period = Number(fs.readFileSync('/sys/fs/cgroup/cpu/cpu.cfs_period_us', 'utf8'));
|
|
15
|
+
return quota > 0 && period > 0 ? Math.max(1, Math.floor(quota / period)) : null;
|
|
16
|
+
}
|
|
17
|
+
catch (e) { }
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
const getAvailableCpus = () => {
|
|
21
|
+
const override = parseInt(process.env.WEBPACK_PARALLELISM || '', 10);
|
|
22
|
+
if (override > 0) {
|
|
23
|
+
return override;
|
|
24
|
+
}
|
|
25
|
+
const cpus = typeof os.availableParallelism === 'function' ? os.availableParallelism() : os.cpus().length;
|
|
26
|
+
const limit = getCgroupCpuLimit();
|
|
27
|
+
return Math.max(1, limit === null ? cpus : Math.min(cpus, limit));
|
|
28
|
+
};
|
|
29
|
+
exports.getAvailableCpus = getAvailableCpus;
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@studyportals/webpack-helper",
|
|
3
|
-
"version": "8.0.0",
|
|
3
|
+
"version": "8.2.0-beta.0",
|
|
4
4
|
"description": "A collection of standard configurations and helpers for webpack.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/main.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "vitest --watch=false --coverage",
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"
|
|
10
|
-
"postinstall": "cp ./assets/.browserslistrc ../../../ || true",
|
|
11
|
-
"
|
|
8
|
+
"build": "rm -rf dist && tsc",
|
|
9
|
+
"prepublishOnly": "npm run build",
|
|
10
|
+
"postinstall": "test -d ../../../ && cp ./assets/.browserslistrc ../../../ || true",
|
|
11
|
+
"version:alpha": "sh ./scripts/version.sh alpha",
|
|
12
|
+
"version:beta": "sh ./scripts/version.sh beta",
|
|
13
|
+
"version:latest": "sh ./scripts/version.sh latest",
|
|
14
|
+
"release": "sh ./scripts/release.sh"
|
|
12
15
|
},
|
|
13
16
|
"files": [
|
|
14
|
-
"
|
|
17
|
+
"dist",
|
|
15
18
|
"assets/*"
|
|
16
19
|
],
|
|
17
20
|
"author": {
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
"license": "ISC",
|
|
22
25
|
"dependencies": {
|
|
23
26
|
"@studyportals/bob-manifest-generator": "^5.0.1",
|
|
24
|
-
"@studyportals/browserslist-config": "^
|
|
27
|
+
"@studyportals/browserslist-config": "^2.0.0",
|
|
25
28
|
"@studyportals/dll-availability-tracker": "^2.0.0",
|
|
26
29
|
"@studyportals/vue-config": "^5.0.3",
|
|
27
30
|
"css-loader": "^6.10.0",
|
|
@@ -30,6 +33,7 @@
|
|
|
30
33
|
"esbuild-plugin-browserslist": "^0.11.1",
|
|
31
34
|
"file-loader": "^6.2.0",
|
|
32
35
|
"fork-ts-checker-webpack-plugin": "^9.0.2",
|
|
36
|
+
"lightningcss": "^1.33.0",
|
|
33
37
|
"mini-css-extract-plugin": "^2.8.0",
|
|
34
38
|
"path": "^0.12.7",
|
|
35
39
|
"prettier": "^2.8.8",
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProductionConfig = void 0;
|
|
4
|
-
const webpack = require('webpack');
|
|
5
|
-
const cssMinimizerPlugin = require('css-minimizer-webpack-plugin');
|
|
6
|
-
const DllAvailabilityTracker = require('@studyportals/dll-availability-tracker');
|
|
7
|
-
const ProductionConfig = (bobConfig) => {
|
|
8
|
-
let dllDependencies = ['library'];
|
|
9
|
-
if (bobConfig && bobConfig.hasOwnProperty('dllPackages')) {
|
|
10
|
-
bobConfig.dllPackages.forEach((dependency) => dllDependencies.push(dependency.manifest.name));
|
|
11
|
-
}
|
|
12
|
-
return {
|
|
13
|
-
plugins: [
|
|
14
|
-
new webpack.DefinePlugin({
|
|
15
|
-
'process.env': {
|
|
16
|
-
NODE_ENV: '"production"'
|
|
17
|
-
}
|
|
18
|
-
}),
|
|
19
|
-
new cssMinimizerPlugin({
|
|
20
|
-
minimizerOptions: {
|
|
21
|
-
preset: [
|
|
22
|
-
'default',
|
|
23
|
-
{
|
|
24
|
-
discardComments: {
|
|
25
|
-
removeAll: true
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
]
|
|
29
|
-
},
|
|
30
|
-
}),
|
|
31
|
-
new DllAvailabilityTracker({
|
|
32
|
-
dependencies: dllDependencies || []
|
|
33
|
-
})
|
|
34
|
-
],
|
|
35
|
-
optimization: {
|
|
36
|
-
minimize: true,
|
|
37
|
-
minimizer: [
|
|
38
|
-
compiler => {
|
|
39
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
40
|
-
new TerserPlugin({
|
|
41
|
-
parallel: true,
|
|
42
|
-
extractComments: false,
|
|
43
|
-
terserOptions: {
|
|
44
|
-
output: {
|
|
45
|
-
comments: false
|
|
46
|
-
},
|
|
47
|
-
compress: {
|
|
48
|
-
drop_console: true,
|
|
49
|
-
passes: 5
|
|
50
|
-
},
|
|
51
|
-
sourceMap: true
|
|
52
|
-
}
|
|
53
|
-
}).apply(compiler);
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
exports.ProductionConfig = ProductionConfig;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → dist}/main.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|