@studyportals/webpack-helper 6.0.5-3 → 6.0.7-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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@studyportals/webpack-helper",
3
- "version": "6.0.5-3",
3
+ "version": "6.0.7-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": "cp ./assets/.browserslistrc ../../../",
11
- "deploy-beta": "npm version prerelease && npm run build && npm publish --tag beta --access=public && rm -rf node_modules"
10
+ "postinstall": "sudo cp ./assets/.browserslistrc ../../../",
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": [
14
14
  "src/**/*.js",
@@ -39,7 +39,8 @@
39
39
  "vue-loader": "^17.4.2",
40
40
  "webpack": "^5.90.3",
41
41
  "webpack-cli": "^5.1.4",
42
- "webpack-merge": "^5.10.0"
42
+ "webpack-merge": "^5.10.0",
43
+ "webpack-retry-chunk-load-plugin": "^3.1.1"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/node": "^20.11.20",
@@ -6,5 +6,4 @@ var Preset;
6
6
  Preset["VUE_TYPESCRIPT"] = "vue-typescript";
7
7
  Preset["TYPESCRIPT"] = "typescript";
8
8
  Preset["JAVASCRIPT"] = "javascript";
9
- Preset["VUE_TYPESCRIPT_NO_CODE_SPLITTING"] = "vue-typescript-no-code-splitting";
10
9
  })(Preset || (exports.Preset = Preset = {}));
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const mode_1 = require("../enums/mode");
4
+ const { RetryChunkLoadPlugin } = require('webpack-retry-chunk-load-plugin');
5
+ class ChunksRetryPluginFactory {
6
+ static InjectPlugin(preset) {
7
+ if (!preset.retryChunksConfig) {
8
+ return preset;
9
+ }
10
+ if (preset.mode === mode_1.Mode.DEVELOPMENT) {
11
+ return preset;
12
+ }
13
+ if (!preset.retryChunksConfig.inject) {
14
+ return preset;
15
+ }
16
+ preset.getPlugins = (filename) => {
17
+ const plugins = preset.getPlugins(filename);
18
+ plugins.push(ChunksRetryPluginFactory.CustomRetryChunksPlugin(preset));
19
+ return plugins;
20
+ };
21
+ return preset;
22
+ }
23
+ static CustomRetryChunksPlugin(preset) {
24
+ const { retryChunksConfig } = preset;
25
+ return new RetryChunkLoadPlugin({
26
+ cacheBust: `function() {
27
+ return Date.now();
28
+ }`,
29
+ retryDelay: `function(retryAttempt) {
30
+ return Math.min(2000, Math.pow(2, retryAttempt) * 100);
31
+ }
32
+ `,
33
+ maxRetries: retryChunksConfig.threshold,
34
+ lastResortScript: ChunksRetryPluginFactory.CreateLastResortScript(preset)
35
+ });
36
+ }
37
+ static CreateLastResortScript(preset) {
38
+ const { retryChunksConfig } = preset;
39
+ let lastResortScript = ``;
40
+ if (retryChunksConfig.thresholdReachedCallBack) {
41
+ lastResortScript = `
42
+ ${retryChunksConfig.thresholdReachedCallBack.toString()}
43
+ `;
44
+ }
45
+ if (!retryChunksConfig.disableDefaultRollbarError) {
46
+ lastResortScript = `
47
+ if (!window || !window['rollbar_PQ'] || !window['rollbar_PQ'].error) {
48
+ return;
49
+ }
50
+
51
+ window['rollbar_PQ'].error(new Error('Failed to load chunk for after retries'));
52
+ `;
53
+ }
54
+ return lastResortScript;
55
+ }
56
+ }
57
+ exports.default = ChunksRetryPluginFactory;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Configuration = void 0;
4
7
  const entry_1 = require("./entry");
@@ -9,13 +12,14 @@ const preset_1 = require("../enums/preset");
9
12
  const vue_typescript_preset_1 = require("../presets/vue-typescript.preset");
10
13
  const typescript_preset_1 = require("../presets/typescript.preset");
11
14
  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
15
  const mode_1 = require("../enums/mode");
14
16
  const production_config_1 = require("../defaults/production.config");
15
17
  const development_config_1 = require("../defaults/development.config");
18
+ const chunks_retry_plugin_factory_1 = __importDefault(require("../factories/chunks-retry-plugin-factory"));
16
19
  const ManifestGenerator = require("@studyportals/bob-manifest-generator").ManifestGenerator;
17
20
  const DllReferencePlugin = require("@studyportals/bob-manifest-generator").DllReferencePlugin;
18
21
  const { merge } = require('webpack-merge');
22
+ const DEFAULT_CHUNKS_RETRY_CONFIG_THRESHOLD = 6;
19
23
  class Configuration {
20
24
  constructor(options) {
21
25
  this.customElementTags = options.customElementTags || [];
@@ -35,6 +39,10 @@ class Configuration {
35
39
  [mode_1.Mode.PRODUCTION]: merge([configPrd, (0, production_config_1.ProductionConfig)(this.bob)]) || (0, production_config_1.ProductionConfig)(this.bob)
36
40
  };
37
41
  this.fileName = options.output.fileName || "[name]";
42
+ this.chunksRetryConfig = options.chunksRetryConfig || {
43
+ threshold: DEFAULT_CHUNKS_RETRY_CONFIG_THRESHOLD,
44
+ inject: this.preset === preset_1.Preset.VUE_TYPESCRIPT
45
+ };
38
46
  }
39
47
  get(mode) {
40
48
  this.detectPresets(mode);
@@ -58,16 +66,13 @@ class Configuration {
58
66
  detectPresets(mode) {
59
67
  switch (this.preset) {
60
68
  case preset_1.Preset.VUE_TYPESCRIPT:
61
- this.injectPreset(new vue_typescript_preset_1.VueTypeScriptPreset(mode, this.customElementTags));
69
+ this.injectPreset(new vue_typescript_preset_1.VueTypeScriptPreset(mode, this.chunksRetryConfig, this.customElementTags));
62
70
  break;
63
71
  case preset_1.Preset.TYPESCRIPT:
64
- this.injectPreset(new typescript_preset_1.TypeScriptPreset());
72
+ this.injectPreset(new typescript_preset_1.TypeScriptPreset(mode, this.chunksRetryConfig));
65
73
  break;
66
74
  case preset_1.Preset.JAVASCRIPT:
67
- this.injectPreset(new javascript_preset_1.JavascriptPreset());
68
- 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));
75
+ this.injectPreset(new javascript_preset_1.JavascriptPreset(mode, this.chunksRetryConfig));
71
76
  break;
72
77
  default:
73
78
  break;
@@ -81,6 +86,7 @@ class Configuration {
81
86
  });
82
87
  this.extensions = this.extensions.concat(preset.getExtensions());
83
88
  this.module.setModule(module);
89
+ chunks_retry_plugin_factory_1.default.InjectPlugin(preset);
84
90
  }
85
91
  getEnvironmentSpecificConfig(mode) {
86
92
  return this.environmentSpecificConfig[mode];
@@ -0,0 +1 @@
1
+ "use strict";
@@ -4,6 +4,10 @@ exports.JavascriptPreset = void 0;
4
4
  const browser_list_to_esbuild_target_factory_1 = require("../factories/browser-list-to-esbuild-target-factory");
5
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
6
  class JavascriptPreset {
7
+ constructor(mode, retryChunksConfig) {
8
+ this.mode = mode;
9
+ this.retryChunksConfig = retryChunksConfig;
10
+ }
7
11
  getPlugins(filename) {
8
12
  return [
9
13
  new MiniCssExtractPlugin({
@@ -26,7 +30,12 @@ class JavascriptPreset {
26
30
  use: [
27
31
  MiniCssExtractPlugin.loader,
28
32
  'css-loader',
29
- 'sass-loader'
33
+ {
34
+ loader: 'sass-loader',
35
+ options: {
36
+ api: 'modern-compiler'
37
+ }
38
+ }
30
39
  ],
31
40
  },
32
41
  {
@@ -4,6 +4,10 @@ exports.TypeScriptPreset = void 0;
4
4
  const browser_list_to_esbuild_target_factory_1 = require("../factories/browser-list-to-esbuild-target-factory");
5
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6
6
  class TypeScriptPreset {
7
+ constructor(mode, retryChunksConfig) {
8
+ this.mode = mode;
9
+ this.retryChunksConfig = retryChunksConfig;
10
+ }
7
11
  getPlugins(filename) {
8
12
  return [
9
13
  new MiniCssExtractPlugin({
@@ -26,7 +30,12 @@ class TypeScriptPreset {
26
30
  use: [
27
31
  MiniCssExtractPlugin.loader,
28
32
  'css-loader',
29
- 'sass-loader'
33
+ {
34
+ loader: 'sass-loader',
35
+ options: {
36
+ api: 'modern-compiler'
37
+ }
38
+ }
30
39
  ],
31
40
  },
32
41
  {
@@ -8,8 +8,9 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
8
8
  const VueLoaderPlugin = require('vue-loader').VueLoaderPlugin;
9
9
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
10
10
  class VueTypeScriptPreset {
11
- constructor(mode, customElementTags) {
11
+ constructor(mode, retryChunksConfig, customElementTags) {
12
12
  this.mode = mode;
13
+ this.retryChunksConfig = retryChunksConfig;
13
14
  this.customElementTags = customElementTags;
14
15
  }
15
16
  getPlugins(filename) {
@@ -40,7 +41,12 @@ class VueTypeScriptPreset {
40
41
  use: [
41
42
  MiniCssExtractPlugin.loader,
42
43
  'css-loader',
43
- 'sass-loader'
44
+ {
45
+ loader: 'sass-loader',
46
+ options: {
47
+ api: 'modern-compiler'
48
+ }
49
+ }
44
50
  ],
45
51
  },
46
52
  {
@@ -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;