@tramvai/cli 2.109.0 → 2.110.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.
@@ -4,25 +4,39 @@ exports.pwaBlock = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const path_1 = tslib_1.__importDefault(require("path"));
6
6
  const workbox_webpack_plugin_1 = require("workbox-webpack-plugin");
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const safeRequire_1 = require("../../../../utils/safeRequire");
7
9
  const PwaIconsPlugin_1 = require("../../plugins/PwaIconsPlugin");
8
10
  const WebManifestPlugin_1 = require("../../plugins/WebManifestPlugin");
9
11
  const shared_1 = require("./shared");
10
12
  const pwaBlock =
11
13
  // eslint-disable-next-line max-statements
12
14
  (configManager) => (config) => {
13
- var _a, _b, _c, _d, _e;
15
+ var _a, _b, _c, _d, _e, _f, _g;
14
16
  const { experiments: { pwa }, rootDir, root, output, env, modern, sourceMap, assetsPrefix, } = configManager;
15
17
  config.batch((0, shared_1.pwaSharedBlock)(configManager));
16
- // @todo check `@tramvai/module-progressive-web-app` is installed
17
- if ((_a = pwa.workbox) === null || _a === void 0 ? void 0 : _a.enabled) {
18
- // @todo check `sw.ts` exists
18
+ if (!(0, safeRequire_1.safeRequireResolve)('@tramvai/module-progressive-web-app') &&
19
+ (((_a = pwa.workbox) === null || _a === void 0 ? void 0 : _a.enabled) || ((_b = pwa.webmanifest) === null || _b === void 0 ? void 0 : _b.enabled))) {
20
+ throw Error('PWA functional requires @tramvai/module-progressive-web-app installed');
21
+ }
22
+ if ((_c = pwa.workbox) === null || _c === void 0 ? void 0 : _c.enabled) {
23
+ const swSrc = path_1.default.join(rootDir, root, (_d = pwa.sw) === null || _d === void 0 ? void 0 : _d.src);
24
+ const swDest = path_1.default.join(rootDir, output.client, (_e = pwa.sw) === null || _e === void 0 ? void 0 : _e.dest);
25
+ if (!fs_1.default.existsSync(swSrc)) {
26
+ throw Error(`PWA workbox enabled but Service Worker source file not found by path ${swSrc}`);
27
+ }
19
28
  // @todo: static HTML caching ??? full offline mode for tramvai static ???
20
29
  const workboxOptions = {
21
- swSrc: path_1.default.join(rootDir, root, (_b = pwa.sw) === null || _b === void 0 ? void 0 : _b.src),
22
- swDest: path_1.default.join(rootDir, output.client, (_c = pwa.sw) === null || _c === void 0 ? void 0 : _c.dest),
30
+ swSrc,
31
+ swDest,
23
32
  exclude: [/hmr\.js$/, /\.map$/, /\.hot-update\./],
24
- // @todo maybe less for production?
25
- maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
33
+ maximumFileSizeToCacheInBytes: env === 'production' ? 5 * 1024 * 1024 : 10 * 1024 * 1024,
34
+ chunks: pwa.workbox.chunks,
35
+ excludeChunks: pwa.workbox.excludeChunks,
36
+ additionalManifestEntries: [
37
+ // @todo CSR fallback or all static pages?
38
+ // do not forget about revision and possible conflict with modifyURLPrefix
39
+ ],
26
40
  };
27
41
  if (pwa.workbox.include) {
28
42
  workboxOptions.include = pwa.workbox.include.map((expr) => new RegExp(expr));
@@ -33,6 +47,12 @@ const pwaBlock =
33
47
  ...pwa.workbox.exclude.map((expr) => new RegExp(expr)),
34
48
  ];
35
49
  }
50
+ if (pwa.workbox.additionalManifestEntries) {
51
+ workboxOptions.additionalManifestEntries = [
52
+ ...workboxOptions.additionalManifestEntries,
53
+ ...pwa.workbox.additionalManifestEntries,
54
+ ];
55
+ }
36
56
  if (env === 'production') {
37
57
  workboxOptions.dontCacheBustURLsMatching = /\/\w+?\.[\w\d]+?\.(js|css|gif|png|jpe?g|svg)$/;
38
58
  workboxOptions.modifyURLPrefix = {
@@ -60,11 +80,11 @@ const pwaBlock =
60
80
  }
61
81
  config.plugin('workbox').use(workboxPlugin);
62
82
  }
63
- if ((_d = pwa.webmanifest) === null || _d === void 0 ? void 0 : _d.enabled) {
83
+ if ((_f = pwa.webmanifest) === null || _f === void 0 ? void 0 : _f.enabled) {
64
84
  const webmanifestPlugin = new WebManifestPlugin_1.WebManifestPlugin(pwa.webmanifest);
65
85
  config.plugin('webmanifest').use(webmanifestPlugin);
66
86
  }
67
- if ((_e = pwa.icon) === null || _e === void 0 ? void 0 : _e.src) {
87
+ if ((_g = pwa.icon) === null || _g === void 0 ? void 0 : _g.src) {
68
88
  const iconSrc = path_1.default.join(rootDir, root, pwa.icon.src);
69
89
  const pwaIconsPlugin = new PwaIconsPlugin_1.PwaIconsPlugin(Object.assign(Object.assign({}, pwa.icon), { src: iconSrc }));
70
90
  config.plugin('pwa-icons').use(pwaIconsPlugin);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../src/library/webpack/blocks/pwa/client.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AAExB,mEAAwD;AAGxD,iEAA8D;AAC9D,uEAAoE;AACpE,qCAA0C;AAEnC,MAAM,QAAQ;AACnB,0CAA0C;AAC1C,CAAC,aAAoD,EAAE,EAAE,CAAC,CAAC,MAAc,EAAE,EAAE;;IAC3E,MAAM,EACJ,WAAW,EAAE,EAAE,GAAG,EAAE,EACpB,OAAO,EACP,IAAI,EACJ,MAAM,EACN,GAAG,EACH,MAAM,EACN,SAAS,EACT,YAAY,GACb,GAAG,aAAa,CAAC;IAElB,MAAM,CAAC,KAAK,CAAC,IAAA,uBAAc,EAAC,aAAa,CAAC,CAAC,CAAC;IAE5C,iEAAiE;IAEjE,IAAI,MAAA,GAAG,CAAC,OAAO,0CAAE,OAAO,EAAE;QACxB,6BAA6B;QAC7B,0EAA0E;QAC1E,MAAM,cAAc,GAA6B;YAC/C,KAAK,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,MAAA,GAAG,CAAC,EAAE,0CAAE,GAAG,CAAC;YAC5C,MAAM,EAAE,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAA,GAAG,CAAC,EAAE,0CAAE,IAAI,CAAC;YACvD,OAAO,EAAE,CAAC,UAAU,EAAE,QAAQ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CAAC,aAAa,CAAC,CAAC;KAC7C;IAED,IAAI,MAAA,GAAG,CAAC,WAAW,0CAAE,OAAO,EAAE;QAC5B,MAAM,iBAAiB,GAAG,IAAI,qCAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAEjE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;KACrD;IAED,IAAI,MAAA,GAAG,CAAC,IAAI,0CAAE,GAAG,EAAE;QACjB,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACvD,MAAM,cAAc,GAAG,IAAI,+BAAc,iCAAM,GAAG,CAAC,IAAI,KAAE,GAAG,EAAE,OAAO,IAAG,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;KAChD;AACH,CAAC,CAAC;AA9GS,QAAA,QAAQ,YA8GjB"}
@@ -18,8 +18,8 @@ class WebManifestPlugin {
18
18
  name: pluginName,
19
19
  stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
20
20
  }, () => {
21
- const manifestFilename = dest;
22
- compilation.emitAsset(manifestFilename, new RawSource(JSON.stringify(content)));
21
+ const manifestFilename = dest.replace(/^\//, '');
22
+ compilation.emitAsset(manifestFilename, new RawSource(JSON.stringify(content, null, 2)));
23
23
  });
24
24
  });
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WebManifestPlugin.js","sourceRoot":"","sources":["../../../../src/library/webpack/plugins/WebManifestPlugin.ts"],"names":[],"mappings":";;;;AAIA,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,MAAa,iBAAiB;IAC5B,YAAoB,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAA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AAI,CAAC,OAAO,EAA5C,EAAE,IAAI,EAAE,OAAO,OAA6B,EAAxB,OAAO,sBAA3B,mBAA6B,CAAe,CAAC;QAEnD,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE,EAAE;YAC7D,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC;gBACE,IAAI,EAAE,UAAU;gBAChB,KAAK,EAAE,WAAW,CAAC,8BAA8B;aAClD,EACD,GAAG,EAAE;gBACH,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAEjD,WAAW,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3F,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzBD,8CAyBC"}
@@ -593,6 +593,46 @@
593
593
  "items": {
594
594
  "type": "string"
595
595
  }
596
+ },
597
+ "chunks": {
598
+ "title": "Array of chunk names used to include in the precache manifest",
599
+ "type": "array",
600
+ "items": {
601
+ "type": "string"
602
+ }
603
+ },
604
+ "excludeChunks": {
605
+ "title": "Array of chunk names used to exclude from the precache manifest",
606
+ "type": "array",
607
+ "items": {
608
+ "type": "string"
609
+ }
610
+ },
611
+ "additionalManifestEntries": {
612
+ "title": "A list of entries to be included in the precache manifest, in addition to any entries that are generated as part of the build configuration",
613
+ "type": "array",
614
+ "items": {
615
+ "anyOf": [
616
+ {
617
+ "type": "object",
618
+ "properties": {
619
+ "integrity": {
620
+ "type": "string"
621
+ },
622
+ "revision": {
623
+ "type": "string"
624
+ },
625
+ "url": {
626
+ "type": "string"
627
+ }
628
+ },
629
+ "additionalProperties": false
630
+ },
631
+ {
632
+ "type": "string"
633
+ }
634
+ ]
635
+ }
596
636
  }
597
637
  },
598
638
  "additionalProperties": false
@@ -705,21 +745,27 @@
705
745
  "type": "object",
706
746
  "properties": {
707
747
  "viewport": {
748
+ "title": "\"viewport\" meta tag",
708
749
  "type": "string"
709
750
  },
710
751
  "themeColor": {
752
+ "title": "\"theme-color\" meta tag",
711
753
  "type": "string"
712
754
  },
713
755
  "mobileApp": {
756
+ "title": "\"mobile-web-app-capable\" meta tag",
714
757
  "type": "string"
715
758
  },
716
759
  "mobileAppIOS": {
760
+ "title": "\"apple-mobile-web-app-capable\" meta tag",
717
761
  "type": "string"
718
762
  },
719
763
  "appleTitle": {
764
+ "title": "\"apple-mobile-web-app-title\" meta tag",
720
765
  "type": "string"
721
766
  },
722
767
  "appleStatusBarStyle": {
768
+ "title": "\"apple-mobile-web-app-status-bar-style\" meta tag",
723
769
  "type": "string"
724
770
  }
725
771
  },
@@ -1,4 +1,5 @@
1
1
  import type { ForkTsCheckerWebpackPluginOptions } from 'fork-ts-checker-webpack-plugin/lib/plugin-options';
2
+ import type { ManifestEntry } from 'workbox-build';
2
3
  import type { PwaIconOptions, PwaMetaOptions, WebManifestOptions } from '../pwa';
3
4
  import type { CliConfigEntry, Experiments } from './cli';
4
5
  import type { OverridableOption } from './common';
@@ -64,6 +65,18 @@ export interface ApplicationExperiments extends Experiments {
64
65
  * @title Array of regexp specifiers used to include assets in the precache manifest
65
66
  */
66
67
  include?: string[];
68
+ /**
69
+ * @title Array of chunk names used to include in the precache manifest
70
+ */
71
+ chunks?: string[];
72
+ /**
73
+ * @title Array of chunk names used to exclude from the precache manifest
74
+ */
75
+ excludeChunks?: string[];
76
+ /**
77
+ * @title A list of entries to be included in the precache manifest, in addition to any entries that are generated as part of the build configuration
78
+ */
79
+ additionalManifestEntries?: Array<string | ManifestEntry>;
67
80
  };
68
81
  /**
69
82
  * @title WebManifest content (manifest.json or webmanifest will be generated based on this options)
@@ -52,10 +52,28 @@ export type PwaIconOptions = {
52
52
  sizes?: number[];
53
53
  };
54
54
  export type PwaMetaOptions = {
55
+ /**
56
+ * @title "viewport" meta tag
57
+ */
55
58
  viewport?: string;
59
+ /**
60
+ * @title "theme-color" meta tag
61
+ */
56
62
  themeColor?: string;
63
+ /**
64
+ * @title "mobile-web-app-capable" meta tag
65
+ */
57
66
  mobileApp?: string;
67
+ /**
68
+ * @title "apple-mobile-web-app-capable" meta tag
69
+ */
58
70
  mobileAppIOS?: string;
71
+ /**
72
+ * @title "apple-mobile-web-app-title" meta tag
73
+ */
59
74
  appleTitle?: string;
75
+ /**
76
+ * @title "apple-mobile-web-app-status-bar-style" meta tag
77
+ */
60
78
  appleStatusBarStyle?: string;
61
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/cli",
3
- "version": "2.109.0",
3
+ "version": "2.110.0",
4
4
  "description": "Cli инструмент для сборки и запуска приложений",
5
5
  "files": [
6
6
  "src",
@@ -71,7 +71,7 @@
71
71
  "@tinkoff/utils": "^2.1.3",
72
72
  "@tinkoff/webpack-dedupe-plugin": "1.0.5",
73
73
  "@tramvai/build": "3.1.3",
74
- "@tramvai/react": "2.109.0",
74
+ "@tramvai/react": "2.110.0",
75
75
  "@tramvai/tools-check-versions": "0.4.14",
76
76
  "@tramvai/tools-migrate": "0.6.18",
77
77
  "ajv": "^6.12.6",
package/schema.json CHANGED
@@ -614,6 +614,46 @@
614
614
  "items": {
615
615
  "type": "string"
616
616
  }
617
+ },
618
+ "chunks": {
619
+ "title": "Array of chunk names used to include in the precache manifest",
620
+ "type": "array",
621
+ "items": {
622
+ "type": "string"
623
+ }
624
+ },
625
+ "excludeChunks": {
626
+ "title": "Array of chunk names used to exclude from the precache manifest",
627
+ "type": "array",
628
+ "items": {
629
+ "type": "string"
630
+ }
631
+ },
632
+ "additionalManifestEntries": {
633
+ "title": "A list of entries to be included in the precache manifest, in addition to any entries that are generated as part of the build configuration",
634
+ "type": "array",
635
+ "items": {
636
+ "anyOf": [
637
+ {
638
+ "type": "object",
639
+ "properties": {
640
+ "integrity": {
641
+ "type": "string"
642
+ },
643
+ "revision": {
644
+ "type": "string"
645
+ },
646
+ "url": {
647
+ "type": "string"
648
+ }
649
+ },
650
+ "additionalProperties": false
651
+ },
652
+ {
653
+ "type": "string"
654
+ }
655
+ ]
656
+ }
617
657
  }
618
658
  },
619
659
  "additionalProperties": false
@@ -726,21 +766,27 @@
726
766
  "type": "object",
727
767
  "properties": {
728
768
  "viewport": {
769
+ "title": "\"viewport\" meta tag",
729
770
  "type": "string"
730
771
  },
731
772
  "themeColor": {
773
+ "title": "\"theme-color\" meta tag",
732
774
  "type": "string"
733
775
  },
734
776
  "mobileApp": {
777
+ "title": "\"mobile-web-app-capable\" meta tag",
735
778
  "type": "string"
736
779
  },
737
780
  "mobileAppIOS": {
781
+ "title": "\"apple-mobile-web-app-capable\" meta tag",
738
782
  "type": "string"
739
783
  },
740
784
  "appleTitle": {
785
+ "title": "\"apple-mobile-web-app-title\" meta tag",
741
786
  "type": "string"
742
787
  },
743
788
  "appleStatusBarStyle": {
789
+ "title": "\"apple-mobile-web-app-status-bar-style\" meta tag",
744
790
  "type": "string"
745
791
  }
746
792
  },
@@ -1,8 +1,10 @@
1
1
  import path from 'path';
2
2
  import type Config from 'webpack-chain';
3
3
  import { InjectManifest } from 'workbox-webpack-plugin';
4
+ import fs from 'fs';
4
5
  import type { ConfigManager } from '../../../../config/configManager';
5
6
  import type { ApplicationConfigEntry } from '../../../../typings/configEntry/application';
7
+ import { safeRequireResolve } from '../../../../utils/safeRequire';
6
8
  import { PwaIconsPlugin } from '../../plugins/PwaIconsPlugin';
7
9
  import { WebManifestPlugin } from '../../plugins/WebManifestPlugin';
8
10
  import { pwaSharedBlock } from './shared';
@@ -23,17 +25,35 @@ export const pwaBlock =
23
25
 
24
26
  config.batch(pwaSharedBlock(configManager));
25
27
 
26
- // @todo check `@tramvai/module-progressive-web-app` is installed
28
+ if (
29
+ !safeRequireResolve('@tramvai/module-progressive-web-app') &&
30
+ (pwa.workbox?.enabled || pwa.webmanifest?.enabled)
31
+ ) {
32
+ throw Error('PWA functional requires @tramvai/module-progressive-web-app installed');
33
+ }
27
34
 
28
35
  if (pwa.workbox?.enabled) {
29
- // @todo check `sw.ts` exists
36
+ const swSrc = path.join(rootDir, root, pwa.sw?.src);
37
+ const swDest = path.join(rootDir, output.client, pwa.sw?.dest);
38
+
39
+ if (!fs.existsSync(swSrc)) {
40
+ throw Error(
41
+ `PWA workbox enabled but Service Worker source file not found by path ${swSrc}`
42
+ );
43
+ }
44
+
30
45
  // @todo: static HTML caching ??? full offline mode for tramvai static ???
31
46
  const workboxOptions: InjectManifest['config'] = {
32
- swSrc: path.join(rootDir, root, pwa.sw?.src),
33
- swDest: path.join(rootDir, output.client, pwa.sw?.dest),
47
+ swSrc,
48
+ swDest,
34
49
  exclude: [/hmr\.js$/, /\.map$/, /\.hot-update\./],
35
- // @todo maybe less for production?
36
- maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
50
+ maximumFileSizeToCacheInBytes: env === 'production' ? 5 * 1024 * 1024 : 10 * 1024 * 1024,
51
+ chunks: pwa.workbox.chunks,
52
+ excludeChunks: pwa.workbox.excludeChunks,
53
+ additionalManifestEntries: [
54
+ // @todo CSR fallback or all static pages?
55
+ // do not forget about revision and possible conflict with modifyURLPrefix
56
+ ],
37
57
  };
38
58
 
39
59
  if (pwa.workbox.include) {
@@ -45,6 +65,12 @@ export const pwaBlock =
45
65
  ...pwa.workbox.exclude.map((expr) => new RegExp(expr)),
46
66
  ];
47
67
  }
68
+ if (pwa.workbox.additionalManifestEntries) {
69
+ workboxOptions.additionalManifestEntries = [
70
+ ...workboxOptions.additionalManifestEntries,
71
+ ...pwa.workbox.additionalManifestEntries,
72
+ ];
73
+ }
48
74
 
49
75
  if (env === 'production') {
50
76
  workboxOptions.dontCacheBustURLsMatching = /\/\w+?\.[\w\d]+?\.(js|css|gif|png|jpe?g|svg)$/;
@@ -22,9 +22,9 @@ export class WebManifestPlugin implements webpack.WebpackPluginInstance {
22
22
  stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
23
23
  },
24
24
  () => {
25
- const manifestFilename = dest;
25
+ const manifestFilename = dest.replace(/^\//, '');
26
26
 
27
- compilation.emitAsset(manifestFilename, new RawSource(JSON.stringify(content)));
27
+ compilation.emitAsset(manifestFilename, new RawSource(JSON.stringify(content, null, 2)));
28
28
  }
29
29
  );
30
30
  });
@@ -593,6 +593,46 @@
593
593
  "items": {
594
594
  "type": "string"
595
595
  }
596
+ },
597
+ "chunks": {
598
+ "title": "Array of chunk names used to include in the precache manifest",
599
+ "type": "array",
600
+ "items": {
601
+ "type": "string"
602
+ }
603
+ },
604
+ "excludeChunks": {
605
+ "title": "Array of chunk names used to exclude from the precache manifest",
606
+ "type": "array",
607
+ "items": {
608
+ "type": "string"
609
+ }
610
+ },
611
+ "additionalManifestEntries": {
612
+ "title": "A list of entries to be included in the precache manifest, in addition to any entries that are generated as part of the build configuration",
613
+ "type": "array",
614
+ "items": {
615
+ "anyOf": [
616
+ {
617
+ "type": "object",
618
+ "properties": {
619
+ "integrity": {
620
+ "type": "string"
621
+ },
622
+ "revision": {
623
+ "type": "string"
624
+ },
625
+ "url": {
626
+ "type": "string"
627
+ }
628
+ },
629
+ "additionalProperties": false
630
+ },
631
+ {
632
+ "type": "string"
633
+ }
634
+ ]
635
+ }
596
636
  }
597
637
  },
598
638
  "additionalProperties": false
@@ -705,21 +745,27 @@
705
745
  "type": "object",
706
746
  "properties": {
707
747
  "viewport": {
748
+ "title": "\"viewport\" meta tag",
708
749
  "type": "string"
709
750
  },
710
751
  "themeColor": {
752
+ "title": "\"theme-color\" meta tag",
711
753
  "type": "string"
712
754
  },
713
755
  "mobileApp": {
756
+ "title": "\"mobile-web-app-capable\" meta tag",
714
757
  "type": "string"
715
758
  },
716
759
  "mobileAppIOS": {
760
+ "title": "\"apple-mobile-web-app-capable\" meta tag",
717
761
  "type": "string"
718
762
  },
719
763
  "appleTitle": {
764
+ "title": "\"apple-mobile-web-app-title\" meta tag",
720
765
  "type": "string"
721
766
  },
722
767
  "appleStatusBarStyle": {
768
+ "title": "\"apple-mobile-web-app-status-bar-style\" meta tag",
723
769
  "type": "string"
724
770
  }
725
771
  },
@@ -1,5 +1,6 @@
1
1
  // eslint-disable-next-line no-restricted-imports
2
2
  import type { ForkTsCheckerWebpackPluginOptions } from 'fork-ts-checker-webpack-plugin/lib/plugin-options';
3
+ import type { ManifestEntry } from 'workbox-build';
3
4
  import type { PwaIconOptions, PwaMetaOptions, WebManifestOptions } from '../pwa';
4
5
  import type { CliConfigEntry, Experiments } from './cli';
5
6
  import type { OverridableOption } from './common';
@@ -68,6 +69,18 @@ export interface ApplicationExperiments extends Experiments {
68
69
  * @title Array of regexp specifiers used to include assets in the precache manifest
69
70
  */
70
71
  include?: string[];
72
+ /**
73
+ * @title Array of chunk names used to include in the precache manifest
74
+ */
75
+ chunks?: string[];
76
+ /**
77
+ * @title Array of chunk names used to exclude from the precache manifest
78
+ */
79
+ excludeChunks?: string[];
80
+ /**
81
+ * @title A list of entries to be included in the precache manifest, in addition to any entries that are generated as part of the build configuration
82
+ */
83
+ additionalManifestEntries?: Array<string | ManifestEntry>;
71
84
  };
72
85
  /**
73
86
  * @title WebManifest content (manifest.json or webmanifest will be generated based on this options)
@@ -53,14 +53,31 @@ export type PwaIconOptions = {
53
53
  * @default [36, 48, 72, 96, 144, 192, 512]
54
54
  */
55
55
  sizes?: number[];
56
- // @todo: dest directory
57
56
  };
58
57
 
59
58
  export type PwaMetaOptions = {
59
+ /**
60
+ * @title "viewport" meta tag
61
+ */
60
62
  viewport?: string;
63
+ /**
64
+ * @title "theme-color" meta tag
65
+ */
61
66
  themeColor?: string;
67
+ /**
68
+ * @title "mobile-web-app-capable" meta tag
69
+ */
62
70
  mobileApp?: string;
71
+ /**
72
+ * @title "apple-mobile-web-app-capable" meta tag
73
+ */
63
74
  mobileAppIOS?: string;
75
+ /**
76
+ * @title "apple-mobile-web-app-title" meta tag
77
+ */
64
78
  appleTitle?: string;
79
+ /**
80
+ * @title "apple-mobile-web-app-status-bar-style" meta tag
81
+ */
65
82
  appleStatusBarStyle?: string;
66
83
  };