@genesislcap/webpack-builder 15.80.0 → 15.81.0-GENC-1660.10

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
@@ -25,6 +25,14 @@ install it, so an app that sets `pwa` needs it in its own devDependencies:
25
25
  npm install --save-dev webpack-pwa-manifest@^4.3.0
26
26
  ```
27
27
 
28
+ # Service worker
29
+
30
+ The `serviceWorker` option compiles `serviceWorker.worker` to `assetName` (default: the worker's file
31
+ name with a `.js` extension), with Workbox `InjectManifest` filling `self.__WB_MANIFEST`. Set
32
+ `precache: false` to compile a worker that doesn't precache. Without `registration`, genx adds an
33
+ entry that registers the worker once the page has loaded; set `registration: false` when the app
34
+ registers the worker itself.
35
+
28
36
 
29
37
 
30
38
  ## Installation
@@ -1 +1 @@
1
- {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/config/entry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,eAAO,MAAM,KAAK,GAAI,KAAK,YAAY,KAAG,aAAa,CAAC,OAAO,CAkB9D,CAAC"}
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../../src/config/entry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,eAAO,MAAM,KAAK,GAAI,KAAK,YAAY,KAAG,aAAa,CAAC,OAAO,CAoB9D,CAAC"}
@@ -2,16 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.entry = void 0;
4
4
  const node_path_1 = require("node:path");
5
+ const build_kit_1 = require("@genesislcap/build-kit");
5
6
  const federation_1 = require("./federation");
7
+ const serviceWorker_1 = require("./serviceWorker");
6
8
  const entry = (ctx) => {
7
9
  const { dirs: { cwd }, config: { serviceWorker }, } = ctx;
8
10
  const main = (0, federation_1.federatedIndexExists)()
9
11
  ? (0, federation_1.resolveFederatedIndex)()
10
12
  : (0, node_path_1.resolve)(cwd, './src/' + 'index.ts');
11
- if (serviceWorker === null || serviceWorker === void 0 ? void 0 : serviceWorker.registration) {
13
+ if (serviceWorker && serviceWorker.registration !== false) {
12
14
  return {
13
15
  main,
14
- swRegistration: (0, node_path_1.resolve)(cwd, './src/' + serviceWorker.registration),
16
+ swRegistration: serviceWorker.registration
17
+ ? (0, node_path_1.resolve)(cwd, './src/' + (0, build_kit_1.getSrcRelativePath)(serviceWorker.registration))
18
+ : (0, serviceWorker_1.serviceWorkerRegistrationEntry)(serviceWorker),
15
19
  };
16
20
  }
17
21
  return main;
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/config/plugins.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAkC7C,eAAO,MAAM,OAAO,GAAI,KAAK,YAAY,KAAG,aAAa,CAAC,SAAS,CA8ElE,CAAC"}
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../src/config/plugins.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAkC7C,eAAO,MAAM,OAAO,GAAI,KAAK,YAAY,KAAG,aAAa,CAAC,SAAS,CAwElE,CAAC"}
@@ -12,8 +12,8 @@ const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extr
12
12
  const webpack_1 = require("webpack");
13
13
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
14
14
  const webpackbar_1 = tslib_1.__importDefault(require("webpackbar"));
15
- const workbox_webpack_plugin_1 = require("workbox-webpack-plugin");
16
15
  const federation_1 = require("./federation");
16
+ const serviceWorker_1 = require("./serviceWorker");
17
17
  const createPwaManifestPlugin = (options) => {
18
18
  let PwaManifestPlugin;
19
19
  try {
@@ -86,13 +86,7 @@ const plugins = (ctx) => {
86
86
  sizes: icon.sizes,
87
87
  src: (0, node_path_1.resolve)(cwd, icon.src),
88
88
  })) })),
89
- serviceWorker &&
90
- new workbox_webpack_plugin_1.InjectManifest({
91
- swSrc: './src/' + serviceWorker.worker,
92
- swDest: serviceWorker.assetName,
93
- exclude: serviceWorker.exclude,
94
- maximumFileSizeToCacheInBytes: serviceWorker.maximumFileSizeToCache,
95
- }),
89
+ serviceWorker && (0, serviceWorker_1.serviceWorkerPlugin)(serviceWorker),
96
90
  ].filter(Boolean);
97
91
  };
98
92
  exports.plugins = plugins;
@@ -0,0 +1,20 @@
1
+ import type { BuildContext } from '@genesislcap/build-kit';
2
+ import type { Compiler } from 'webpack';
3
+ import { InjectManifest } from 'workbox-webpack-plugin';
4
+ type ServiceWorkerConfig = BuildContext['config']['serviceWorker'];
5
+ /**
6
+ * Compiles the worker the way `InjectManifest` does, without injecting a precache manifest.
7
+ */
8
+ export declare class CompileServiceWorkerPlugin {
9
+ private readonly swSrc;
10
+ private readonly swDest;
11
+ constructor(swSrc: string, swDest: string);
12
+ apply(compiler: Compiler): void;
13
+ }
14
+ export declare const serviceWorkerPlugin: (serviceWorker: ServiceWorkerConfig) => CompileServiceWorkerPlugin | InjectManifest;
15
+ /**
16
+ * Entry that registers the worker when the genx config has no `serviceWorker.registration`.
17
+ */
18
+ export declare const serviceWorkerRegistrationEntry: (serviceWorker: ServiceWorkerConfig) => string;
19
+ export {};
20
+ //# sourceMappingURL=serviceWorker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serviceWorker.d.ts","sourceRoot":"","sources":["../../src/config/serviceWorker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQ3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,KAAK,mBAAmB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,CAAC;AAInE;;GAEG;AACH,qBAAa,0BAA0B;IAEnC,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;IAGjC,KAAK,CAAC,QAAQ,EAAE,QAAQ;CAiBzB;AAED,eAAO,MAAM,mBAAmB,GAAI,eAAe,mBAAmB,gDAerE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,GAAI,eAAe,mBAAmB,KAAG,MAKnF,CAAC"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serviceWorkerRegistrationEntry = exports.serviceWorkerPlugin = exports.CompileServiceWorkerPlugin = void 0;
4
+ const node_buffer_1 = require("node:buffer");
5
+ const node_path_1 = require("node:path");
6
+ const build_kit_1 = require("@genesislcap/build-kit");
7
+ const webpack_1 = require("webpack");
8
+ const workbox_webpack_plugin_1 = require("workbox-webpack-plugin");
9
+ const COMPILE_PLUGIN_NAME = 'CompileServiceWorkerPlugin';
10
+ /**
11
+ * Compiles the worker the way `InjectManifest` does, without injecting a precache manifest.
12
+ */
13
+ class CompileServiceWorkerPlugin {
14
+ constructor(swSrc, swDest) {
15
+ this.swSrc = swSrc;
16
+ this.swDest = swDest;
17
+ }
18
+ apply(compiler) {
19
+ compiler.hooks.make.tapPromise(COMPILE_PLUGIN_NAME, (compilation) => {
20
+ const childCompiler = compilation.createChildCompiler(COMPILE_PLUGIN_NAME, { filename: this.swDest }, [new webpack_1.EntryPlugin(compiler.context, this.swSrc, (0, node_path_1.parse)(this.swDest).name)]);
21
+ return new Promise((resolve, reject) => {
22
+ childCompiler.runAsChild((error, _entries, childCompilation) => {
23
+ if (error)
24
+ return reject(error);
25
+ compilation.warnings.push(...childCompilation.warnings);
26
+ compilation.errors.push(...childCompilation.errors);
27
+ resolve();
28
+ });
29
+ });
30
+ });
31
+ }
32
+ }
33
+ exports.CompileServiceWorkerPlugin = CompileServiceWorkerPlugin;
34
+ const serviceWorkerPlugin = (serviceWorker) => {
35
+ const swSrc = './src/' + (0, build_kit_1.getSrcRelativePath)(serviceWorker.worker);
36
+ const swDest = (0, build_kit_1.getServiceWorkerAssetName)(serviceWorker);
37
+ if (serviceWorker.precache === false) {
38
+ return new CompileServiceWorkerPlugin(swSrc, swDest);
39
+ }
40
+ // InjectManifest only fills in defaults for options that are absent, not set to undefined
41
+ return new workbox_webpack_plugin_1.InjectManifest(Object.assign(Object.assign({ swSrc,
42
+ swDest }, (serviceWorker.exclude ? { exclude: serviceWorker.exclude } : {})), (serviceWorker.maximumFileSizeToCache
43
+ ? { maximumFileSizeToCacheInBytes: serviceWorker.maximumFileSizeToCache }
44
+ : {})));
45
+ };
46
+ exports.serviceWorkerPlugin = serviceWorkerPlugin;
47
+ /**
48
+ * Entry that registers the worker when the genx config has no `serviceWorker.registration`.
49
+ */
50
+ const serviceWorkerRegistrationEntry = (serviceWorker) => {
51
+ const source = (0, build_kit_1.createServiceWorkerRegistration)((0, build_kit_1.getServiceWorkerUrl)((0, build_kit_1.getPublicPath)(), serviceWorker));
52
+ return `data:text/javascript;base64,${node_buffer_1.Buffer.from(source).toString('base64')}`;
53
+ };
54
+ exports.serviceWorkerRegistrationEntry = serviceWorkerRegistrationEntry;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/webpack-builder",
3
3
  "description": "Webpack builder",
4
- "version": "15.80.0",
4
+ "version": "15.81.0-GENC-1660.10",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -13,11 +13,12 @@
13
13
  "copyfiles": "copyfiles --verbose public/*.* ./dist",
14
14
  "clean": "rimraf dist temp tsconfig.tsbuildinfo",
15
15
  "dev": "tsc -b ./tsconfig.json -w",
16
+ "test": "uvu -r tsx/cjs test 'test.ts'",
16
17
  "lint": "genx lint -l ox",
17
18
  "lint:fix": "genx lint -l ox --fix"
18
19
  },
19
20
  "dependencies": {
20
- "@genesislcap/build-kit": "15.80.0",
21
+ "@genesislcap/build-kit": "15.81.0-GENC-1660.10",
21
22
  "@pixability-ui/federated-types": "^0.2.0",
22
23
  "@types/webpack-env": "^1.18.4",
23
24
  "camel-case": "^4.1.2",
@@ -46,6 +47,8 @@
46
47
  "devDependencies": {
47
48
  "copyfiles": "^2.4.1",
48
49
  "pkg-types": "^1.0.2",
50
+ "tsx": "^4.7.0",
51
+ "uvu": "0.5.6",
49
52
  "webpack-pwa-manifest": "^4.3.0"
50
53
  },
51
54
  "peerDependencies": {