@modern-js/app-tools 2.48.0 → 2.48.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.
Files changed (29) hide show
  1. package/dist/cjs/builder/generator/index.js +3 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +49 -0
  4. package/dist/cjs/builder/shared/builderPlugins/index.js +3 -1
  5. package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -3
  6. package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -5
  7. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -8
  8. package/dist/esm/builder/generator/index.js +4 -3
  9. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -1
  10. package/dist/esm/builder/shared/builderPlugins/adapterWorker.js +41 -0
  11. package/dist/esm/builder/shared/builderPlugins/index.js +1 -0
  12. package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +35 -43
  13. package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +24 -32
  14. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +240 -261
  15. package/dist/esm-node/builder/generator/index.js +3 -2
  16. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -1
  17. package/dist/esm-node/builder/shared/builderPlugins/adapterWorker.js +25 -0
  18. package/dist/esm-node/builder/shared/builderPlugins/index.js +1 -0
  19. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +0 -3
  20. package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -5
  21. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +1 -8
  22. package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +2 -0
  23. package/dist/types/builder/shared/builderPlugins/index.d.ts +1 -0
  24. package/dist/types/config/legacy/index.d.ts +1 -1
  25. package/dist/types/defineConfig.d.ts +1 -1
  26. package/dist/types/types/config/index.d.ts +4 -3
  27. package/dist/types/types/config/tools.d.ts +5 -3
  28. package/dist/types/types/index.d.ts +2 -2
  29. package/package.json +21 -21
@@ -49,11 +49,12 @@ async function generateBuilder(options, bundlerType) {
49
49
  return builder;
50
50
  }
51
51
  async function applyBuilderPlugins(builder, options) {
52
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
52
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await Promise.resolve().then(() => __toESM(require("../shared/builderPlugins")));
53
53
  builder.addPlugins([
54
54
  builderPluginAdapterBasic(),
55
55
  builderPluginAdapterSSR(options),
56
- builderPluginAdapterHtml(options)
56
+ builderPluginAdapterHtml(options),
57
+ builderPluginAdapterWorker()
57
58
  ]);
58
59
  const { normalizedConfig } = options;
59
60
  if (!normalizedConfig.output.disableNodePolyfill) {
@@ -33,6 +33,7 @@ __export(adapterSSR_exports, {
33
33
  module.exports = __toCommonJS(adapterSSR_exports);
34
34
  var path = __toESM(require("path"));
35
35
  var import_shared = require("@rsbuild/shared");
36
+ var import_core = require("@rsbuild/core");
36
37
  var import_utils = require("@modern-js/utils");
37
38
  var import_bundlerPlugins = require("../bundlerPlugins");
38
39
  var import_utils2 = require("../../../analyze/utils");
@@ -42,7 +43,7 @@ const builderPluginAdapterSSR = (options) => ({
42
43
  const { normalizedConfig } = options;
43
44
  api.modifyRsbuildConfig((config) => {
44
45
  if (isStreamingSSR(normalizedConfig)) {
45
- return (0, import_shared.mergeRsbuildConfig)(config, {
46
+ return (0, import_core.mergeRsbuildConfig)(config, {
46
47
  html: {
47
48
  inject: "body"
48
49
  }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var adapterWorker_exports = {};
20
+ __export(adapterWorker_exports, {
21
+ builderPluginAdapterWorker: () => builderPluginAdapterWorker
22
+ });
23
+ module.exports = __toCommonJS(adapterWorker_exports);
24
+ var import_path = require("path");
25
+ const getDistPath = (outputConfig, type) => {
26
+ const { distPath } = outputConfig;
27
+ const ret = distPath[type];
28
+ if (typeof ret !== "string") {
29
+ throw new Error(`unknown key ${type} in "output.distPath"`);
30
+ }
31
+ return ret;
32
+ };
33
+ const builderPluginAdapterWorker = () => ({
34
+ name: "builder-plugin-adapter-worker",
35
+ setup(api) {
36
+ api.modifyBundlerChain(async (chain, { isServiceWorker }) => {
37
+ const config = api.getNormalizedConfig();
38
+ if (isServiceWorker) {
39
+ const workerPath = getDistPath(config.output, "worker");
40
+ const filename = import_path.posix.join(workerPath, `[name].js`);
41
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
42
+ }
43
+ });
44
+ }
45
+ });
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ builderPluginAdapterWorker
49
+ });
@@ -18,9 +18,11 @@ module.exports = __toCommonJS(builderPlugins_exports);
18
18
  __reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
19
19
  __reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
20
20
  __reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);
21
+ __reExport(builderPlugins_exports, require("./adapterWorker"), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require("./adapterBasic"),
24
25
  ...require("./adapterHtml"),
25
- ...require("./adapterSSR")
26
+ ...require("./adapterSSR"),
27
+ ...require("./adapterWorker")
26
28
  });
@@ -21,7 +21,6 @@ __export(HtmlAsyncChunkPlugin_exports, {
21
21
  HtmlAsyncChunkPlugin: () => HtmlAsyncChunkPlugin
22
22
  });
23
23
  module.exports = __toCommonJS(HtmlAsyncChunkPlugin_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  class HtmlAsyncChunkPlugin {
26
25
  apply(compiler) {
27
26
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -45,8 +44,6 @@ class HtmlAsyncChunkPlugin {
45
44
  });
46
45
  }
47
46
  constructor(htmlWebpackPlugin) {
48
- (0, import_define_property._)(this, "name", void 0);
49
- (0, import_define_property._)(this, "htmlWebpackPlugin", void 0);
50
47
  this.name = "HtmlAsyncChunkPlugin";
51
48
  this.htmlWebpackPlugin = htmlWebpackPlugin;
52
49
  }
@@ -21,7 +21,6 @@ __export(HtmlBottomTemplate_exports, {
21
21
  BottomTemplatePlugin: () => BottomTemplatePlugin
22
22
  });
23
23
  module.exports = __toCommonJS(HtmlBottomTemplate_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  class BottomTemplatePlugin {
26
25
  apply(compiler) {
27
26
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -44,10 +43,8 @@ ${match}`);
44
43
  });
45
44
  }
46
45
  constructor(htmlWebpackPlugin) {
47
- (0, import_define_property._)(this, "htmlWebpackPlugin", void 0);
48
- (0, import_define_property._)(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
49
- (0, import_define_property._)(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
50
- (0, import_define_property._)(this, "name", void 0);
46
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
47
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
51
48
  this.htmlWebpackPlugin = htmlWebpackPlugin;
52
49
  this.name = "bottom-template";
53
50
  }
@@ -21,7 +21,6 @@ __export(RouterPlugin_exports, {
21
21
  RouterPlugin: () => RouterPlugin
22
22
  });
23
23
  module.exports = __toCommonJS(RouterPlugin_exports);
24
- var import_define_property = require("@swc/helpers/_/_define_property");
25
24
  var import_crypto = require("crypto");
26
25
  var import_lodash = require("@modern-js/utils/lodash");
27
26
  var import_utils = require("@modern-js/utils");
@@ -229,13 +228,7 @@ class RouterPlugin {
229
228
  });
230
229
  }
231
230
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
232
- (0, import_define_property._)(this, "name", "RouterPlugin");
233
- (0, import_define_property._)(this, "HtmlBundlerPlugin", void 0);
234
- (0, import_define_property._)(this, "enableInlineRouteManifests", void 0);
235
- (0, import_define_property._)(this, "staticJsDir", void 0);
236
- (0, import_define_property._)(this, "disableFilenameHash", void 0);
237
- (0, import_define_property._)(this, "scriptLoading", void 0);
238
- (0, import_define_property._)(this, "nonce", void 0);
231
+ this.name = "RouterPlugin";
239
232
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
240
233
  this.enableInlineRouteManifests = enableInlineRouteManifests;
241
234
  this.staticJsDir = staticJsDir;
@@ -48,7 +48,7 @@ function applyBuilderPlugins(builder, options) {
48
48
  }
49
49
  function _applyBuilderPlugins() {
50
50
  _applyBuilderPlugins = _async_to_generator(function(builder, options) {
51
- var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, normalizedConfig, pluginNodePolyfill;
51
+ var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker, normalizedConfig, pluginNodePolyfill;
52
52
  return _ts_generator(this, function(_state) {
53
53
  switch (_state.label) {
54
54
  case 0:
@@ -57,11 +57,12 @@ function _applyBuilderPlugins() {
57
57
  import("../shared/builderPlugins")
58
58
  ];
59
59
  case 1:
60
- _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR;
60
+ _ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR, builderPluginAdapterWorker = _ref.builderPluginAdapterWorker;
61
61
  builder.addPlugins([
62
62
  builderPluginAdapterBasic(),
63
63
  builderPluginAdapterSSR(options),
64
- builderPluginAdapterHtml(options)
64
+ builderPluginAdapterHtml(options),
65
+ builderPluginAdapterWorker()
65
66
  ]);
66
67
  normalizedConfig = options.normalizedConfig;
67
68
  if (!!normalizedConfig.output.disableNodePolyfill)
@@ -1,7 +1,8 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as path from "path";
4
- import { isHtmlDisabled, mergeRsbuildConfig } from "@rsbuild/shared";
4
+ import { isHtmlDisabled } from "@rsbuild/shared";
5
+ import { mergeRsbuildConfig } from "@rsbuild/core";
5
6
  import { isSSR, fs } from "@modern-js/utils";
6
7
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
7
8
  import { getServerCombinedModueFile } from "../../../analyze/utils";
@@ -0,0 +1,41 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { posix } from "path";
4
+ var getDistPath = function(outputConfig, type) {
5
+ var distPath = outputConfig.distPath;
6
+ var ret = distPath[type];
7
+ if (typeof ret !== "string") {
8
+ throw new Error("unknown key ".concat(type, ' in "output.distPath"'));
9
+ }
10
+ return ret;
11
+ };
12
+ var builderPluginAdapterWorker = function() {
13
+ return {
14
+ name: "builder-plugin-adapter-worker",
15
+ setup: function setup(api) {
16
+ api.modifyBundlerChain(function() {
17
+ var _ref = _async_to_generator(function(chain, param) {
18
+ var isServiceWorker, config, workerPath, filename;
19
+ return _ts_generator(this, function(_state) {
20
+ isServiceWorker = param.isServiceWorker;
21
+ config = api.getNormalizedConfig();
22
+ if (isServiceWorker) {
23
+ workerPath = getDistPath(config.output, "worker");
24
+ filename = posix.join(workerPath, "[name].js");
25
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
26
+ }
27
+ return [
28
+ 2
29
+ ];
30
+ });
31
+ });
32
+ return function(chain, _) {
33
+ return _ref.apply(this, arguments);
34
+ };
35
+ }());
36
+ }
37
+ };
38
+ };
39
+ export {
40
+ builderPluginAdapterWorker
41
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./adapterWorker";
@@ -1,57 +1,49 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
3
  var HtmlAsyncChunkPlugin = /* @__PURE__ */ function() {
6
4
  "use strict";
7
5
  function HtmlAsyncChunkPlugin2(htmlWebpackPlugin) {
8
6
  _class_call_check(this, HtmlAsyncChunkPlugin2);
9
- _define_property(this, "name", void 0);
10
- _define_property(this, "htmlWebpackPlugin", void 0);
11
7
  this.name = "HtmlAsyncChunkPlugin";
12
8
  this.htmlWebpackPlugin = htmlWebpackPlugin;
13
9
  }
14
- _create_class(HtmlAsyncChunkPlugin2, [
15
- {
16
- key: "apply",
17
- value: function apply(compiler) {
18
- var _this = this;
19
- compiler.hooks.compilation.tap(this.name, function(compilation) {
20
- var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
21
- hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
22
- var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
23
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
24
- try {
25
- for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
26
- var tag = _step.value;
27
- if (tag.tagName === "script") {
28
- var attributes = tag.attributes;
29
- if (attributes && attributes.defer === true) {
30
- attributes.async = true;
31
- delete attributes.defer;
32
- }
33
- }
34
- }
35
- } catch (err) {
36
- _didIteratorError = true;
37
- _iteratorError = err;
38
- } finally {
39
- try {
40
- if (!_iteratorNormalCompletion && _iterator.return != null) {
41
- _iterator.return();
42
- }
43
- } finally {
44
- if (_didIteratorError) {
45
- throw _iteratorError;
46
- }
10
+ var _proto = HtmlAsyncChunkPlugin2.prototype;
11
+ _proto.apply = function apply(compiler) {
12
+ var _this = this;
13
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
14
+ var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
15
+ hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
16
+ var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
17
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
18
+ try {
19
+ for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
20
+ var tag = _step.value;
21
+ if (tag.tagName === "script") {
22
+ var attributes = tag.attributes;
23
+ if (attributes && attributes.defer === true) {
24
+ attributes.async = true;
25
+ delete attributes.defer;
47
26
  }
48
27
  }
49
- return assets;
50
- });
51
- });
52
- }
53
- }
54
- ]);
28
+ }
29
+ } catch (err) {
30
+ _didIteratorError = true;
31
+ _iteratorError = err;
32
+ } finally {
33
+ try {
34
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
35
+ _iterator.return();
36
+ }
37
+ } finally {
38
+ if (_didIteratorError) {
39
+ throw _iteratorError;
40
+ }
41
+ }
42
+ }
43
+ return assets;
44
+ });
45
+ });
46
+ };
55
47
  return HtmlAsyncChunkPlugin2;
56
48
  }();
57
49
  export {
@@ -1,43 +1,35 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
2
  var BottomTemplatePlugin = /* @__PURE__ */ function() {
5
3
  "use strict";
6
4
  function BottomTemplatePlugin2(htmlWebpackPlugin) {
7
5
  _class_call_check(this, BottomTemplatePlugin2);
8
- _define_property(this, "htmlWebpackPlugin", void 0);
9
- _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
10
- _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
11
- _define_property(this, "name", void 0);
6
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
7
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
12
8
  this.htmlWebpackPlugin = htmlWebpackPlugin;
13
9
  this.name = "bottom-template";
14
10
  }
15
- _create_class(BottomTemplatePlugin2, [
16
- {
17
- key: "apply",
18
- value: function apply(compiler) {
19
- var _this = this;
20
- compiler.hooks.compilation.tap(this.name, function(compilation) {
21
- _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
22
- var _data_plugin_options;
23
- if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
24
- return data;
25
- }
26
- if (_this.bottomTemplateReg.test(data.html)) {
27
- data.html = data.html.replace(_this.bottomTemplateReg, "");
28
- var bottomTemplate = data.plugin.options.bottomTemplate;
29
- if (bottomTemplate) {
30
- data.html = data.html.replace(_this.bodyRegExp, function(match) {
31
- return "\n".concat(bottomTemplate, "\n").concat(match);
32
- });
33
- }
34
- }
35
- return data;
36
- });
37
- });
38
- }
39
- }
40
- ]);
11
+ var _proto = BottomTemplatePlugin2.prototype;
12
+ _proto.apply = function apply(compiler) {
13
+ var _this = this;
14
+ compiler.hooks.compilation.tap(this.name, function(compilation) {
15
+ _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
16
+ var _data_plugin_options;
17
+ if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
18
+ return data;
19
+ }
20
+ if (_this.bottomTemplateReg.test(data.html)) {
21
+ data.html = data.html.replace(_this.bottomTemplateReg, "");
22
+ var bottomTemplate = data.plugin.options.bottomTemplate;
23
+ if (bottomTemplate) {
24
+ data.html = data.html.replace(_this.bodyRegExp, function(match) {
25
+ return "\n".concat(bottomTemplate, "\n").concat(match);
26
+ });
27
+ }
28
+ }
29
+ return data;
30
+ });
31
+ });
32
+ };
41
33
  return BottomTemplatePlugin2;
42
34
  }();
43
35
  export {
@@ -1,7 +1,5 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
3
- import { _ as _create_class } from "@swc/helpers/_/_create_class";
4
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
5
3
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
6
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
7
5
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
@@ -18,13 +16,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
18
16
  function RouterPlugin2(param) {
19
17
  var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
20
18
  _class_call_check(this, RouterPlugin2);
21
- _define_property(this, "name", "RouterPlugin");
22
- _define_property(this, "HtmlBundlerPlugin", void 0);
23
- _define_property(this, "enableInlineRouteManifests", void 0);
24
- _define_property(this, "staticJsDir", void 0);
25
- _define_property(this, "disableFilenameHash", void 0);
26
- _define_property(this, "scriptLoading", void 0);
27
- _define_property(this, "nonce", void 0);
19
+ this.name = "RouterPlugin";
28
20
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
29
21
  this.enableInlineRouteManifests = enableInlineRouteManifests;
30
22
  this.staticJsDir = staticJsDir;
@@ -32,276 +24,263 @@ var RouterPlugin = /* @__PURE__ */ function() {
32
24
  this.scriptLoading = scriptLoading;
33
25
  this.nonce = nonce;
34
26
  }
35
- _create_class(RouterPlugin2, [
36
- {
37
- key: "isTargetNodeOrWebWorker",
38
- value: function isTargetNodeOrWebWorker(target) {
39
- if (target === "node" || Array.isArray(target) && target.includes("node")) {
40
- return true;
41
- }
42
- if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
43
- return true;
44
- }
45
- return false;
46
- }
47
- },
48
- {
49
- key: "getEntryChunks",
50
- value: function getEntryChunks(compilation, chunks) {
51
- var entrypointsArray = Array.from(compilation.entrypoints.entries());
52
- var entryChunkIds = entrypointsArray.map(function(entrypoint) {
53
- return entrypoint[0];
54
- });
55
- var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
56
- var _chunk_names;
57
- return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
58
- return entryChunkIds.includes(name);
59
- });
60
- });
61
- return entryChunks;
62
- }
63
- },
64
- {
65
- key: "getEntryChunkFiles",
66
- value: function getEntryChunkFiles(entryChunks) {
67
- return entryChunks.map(function(chunk) {
68
- return _to_consumable_array(chunk.files || []).find(function(fname) {
69
- return fname.includes(".js");
70
- });
71
- });
27
+ var _proto = RouterPlugin2.prototype;
28
+ _proto.isTargetNodeOrWebWorker = function isTargetNodeOrWebWorker(target) {
29
+ if (target === "node" || Array.isArray(target) && target.includes("node")) {
30
+ return true;
31
+ }
32
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
33
+ return true;
34
+ }
35
+ return false;
36
+ };
37
+ _proto.getEntryChunks = function getEntryChunks(compilation, chunks) {
38
+ var entrypointsArray = Array.from(compilation.entrypoints.entries());
39
+ var entryChunkIds = entrypointsArray.map(function(entrypoint) {
40
+ return entrypoint[0];
41
+ });
42
+ var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
43
+ var _chunk_names;
44
+ return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
45
+ return entryChunkIds.includes(name);
46
+ });
47
+ });
48
+ return entryChunks;
49
+ };
50
+ _proto.getEntryChunkFiles = function getEntryChunkFiles(entryChunks) {
51
+ return entryChunks.map(function(chunk) {
52
+ return _to_consumable_array(chunk.files || []).find(function(fname) {
53
+ return fname.includes(".js");
54
+ });
55
+ });
56
+ };
57
+ _proto.apply = function apply(compiler) {
58
+ var _this = this;
59
+ var target = compiler.options.target;
60
+ if (this.isTargetNodeOrWebWorker(target)) {
61
+ return;
62
+ }
63
+ var webpack = compiler.webpack;
64
+ var isRspack = "rspackVersion" in webpack;
65
+ var Compilation = webpack.Compilation, sources = webpack.sources;
66
+ var RawSource = sources.RawSource;
67
+ var normalizePath = function(path) {
68
+ if (!path.endsWith("/")) {
69
+ return "".concat(path, "/");
72
70
  }
73
- },
74
- {
75
- key: "apply",
76
- value: function apply(compiler) {
77
- var _this = this;
78
- var target = compiler.options.target;
79
- if (this.isTargetNodeOrWebWorker(target)) {
80
- return;
81
- }
82
- var webpack = compiler.webpack;
83
- var isRspack = "rspackVersion" in webpack;
84
- var Compilation = webpack.Compilation, sources = webpack.sources;
85
- var RawSource = sources.RawSource;
86
- var normalizePath = function(path) {
87
- if (!path.endsWith("/")) {
88
- return "".concat(path, "/");
89
- }
90
- return path;
91
- };
92
- var chunksToHtmlName = /* @__PURE__ */ new Map();
93
- var ROUTE_MANIFEST_HOLDER = "route-manifest";
94
- var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
95
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
96
- _this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
97
- var outputName = data.outputName;
98
- var chunks = data.plugin.options.chunks;
99
- chunksToHtmlName.set(chunks, outputName);
100
- data.html = data.html.replace("</script>", "</script>".concat(placeholder));
101
- callback(null, data);
102
- });
103
- var _this1 = _this;
104
- compilation.hooks.processAssets.tapPromise({
105
- name: PLUGIN_NAME,
106
- stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
107
- }, /* @__PURE__ */ _async_to_generator(function() {
108
- var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
109
- return _ts_generator(this, function(_state) {
110
- _loop = function(i2) {
111
- var entryName = entryNames[i2];
112
- var file = entryChunkFiles[i2];
113
- var chunkNames = entryChunks[i2].names;
114
- var chunkId = entryChunkFileIds[i2];
115
- var asset = compilation.assets[file];
116
- if (!asset || !chunkId) {
117
- return "continue";
118
- }
119
- var relatedAssets = {};
120
- if (entryChunkFiles.length > 1) {
121
- Object.keys(routeAssets).forEach(function(routeId) {
122
- var segments = routeId.split("_");
123
- var chunkName = segments[0];
124
- if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
125
- relatedAssets[routeId] = routeAssets[routeId];
126
- }
127
- });
128
- } else {
129
- relatedAssets = routeAssets;
130
- }
131
- var manifest2 = {
132
- routeAssets: relatedAssets
133
- };
134
- var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
135
- if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
136
- return v.map(function(item) {
137
- return item.replace(publicPath, "");
138
- });
139
- }
140
- return v;
141
- }), ";\n })();\n ");
142
- var htmlName = void 0;
143
- var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
144
- try {
145
- var _loop2 = function() {
146
- var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
147
- if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
148
- return value === chunks2[index];
149
- })) {
150
- htmlName = name2;
151
- return "break";
152
- }
153
- };
154
- for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
155
- var _ret = _loop2();
156
- if (_ret === "break")
157
- break;
158
- }
159
- } catch (err) {
160
- _didIteratorError2 = true;
161
- _iteratorError2 = err;
162
- } finally {
163
- try {
164
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
165
- _iterator2.return();
166
- }
167
- } finally {
168
- if (_didIteratorError2) {
169
- throw _iteratorError2;
170
- }
171
- }
71
+ return path;
72
+ };
73
+ var chunksToHtmlName = /* @__PURE__ */ new Map();
74
+ var ROUTE_MANIFEST_HOLDER = "route-manifest";
75
+ var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
76
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
77
+ _this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
78
+ var outputName = data.outputName;
79
+ var chunks = data.plugin.options.chunks;
80
+ chunksToHtmlName.set(chunks, outputName);
81
+ data.html = data.html.replace("</script>", "</script>".concat(placeholder));
82
+ callback(null, data);
83
+ });
84
+ var _this1 = _this;
85
+ compilation.hooks.processAssets.tapPromise({
86
+ name: PLUGIN_NAME,
87
+ stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
88
+ }, /* @__PURE__ */ _async_to_generator(function() {
89
+ var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
90
+ return _ts_generator(this, function(_state) {
91
+ _loop = function(i2) {
92
+ var entryName = entryNames[i2];
93
+ var file = entryChunkFiles[i2];
94
+ var chunkNames = entryChunks[i2].names;
95
+ var chunkId = entryChunkFileIds[i2];
96
+ var asset = compilation.assets[file];
97
+ if (!asset || !chunkId) {
98
+ return "continue";
99
+ }
100
+ var relatedAssets = {};
101
+ if (entryChunkFiles.length > 1) {
102
+ Object.keys(routeAssets).forEach(function(routeId) {
103
+ var segments = routeId.split("_");
104
+ var chunkName = segments[0];
105
+ if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
106
+ relatedAssets[routeId] = routeAssets[routeId];
172
107
  }
173
- var oldHtml = compilation.assets[htmlName];
174
- var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
175
- var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
176
- if (oldHtml) {
177
- if (enableInlineRouteManifests) {
178
- compilation.updateAsset(
179
- htmlName,
180
- new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
181
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
182
- void 0
183
- );
184
- } else {
185
- var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
186
- var scriptUrl = "".concat(publicPath).concat(scriptPath);
187
- var scriptLoadingAttr = (
188
- // eslint-disable-next-line no-nested-ternary
189
- scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
190
- );
191
- var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
192
- compilation.updateAsset(
193
- htmlName,
194
- new RawSource(oldHtml.source().toString().replace(placeholder, script)),
195
- // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
196
- void 0
197
- );
198
- compilation.emitAsset(scriptPath, new RawSource(injectedContent));
199
- }
108
+ });
109
+ } else {
110
+ relatedAssets = routeAssets;
111
+ }
112
+ var manifest2 = {
113
+ routeAssets: relatedAssets
114
+ };
115
+ var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
116
+ if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
117
+ return v.map(function(item) {
118
+ return item.replace(publicPath, "");
119
+ });
120
+ }
121
+ return v;
122
+ }), ";\n })();\n ");
123
+ var htmlName = void 0;
124
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
125
+ try {
126
+ var _loop2 = function() {
127
+ var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
128
+ if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
129
+ return value === chunks2[index];
130
+ })) {
131
+ htmlName = name2;
132
+ return "break";
200
133
  }
201
134
  };
202
- stats = compilation.getStats().toJson({
203
- all: false,
204
- publicPath: true,
205
- assets: true,
206
- chunkGroups: true,
207
- chunks: true,
208
- ids: true
209
- });
210
- publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
211
- routeAssets = {};
212
- if (!namedChunkGroups) {
213
- return [
214
- 2
215
- ];
135
+ for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
136
+ var _ret = _loop2();
137
+ if (_ret === "break")
138
+ break;
216
139
  }
217
- prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
218
- prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
219
- routeAssets: {}
220
- });
221
- prevManifest = JSON.parse(prevManifestStr);
222
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
140
+ } catch (err) {
141
+ _didIteratorError2 = true;
142
+ _iteratorError2 = err;
143
+ } finally {
223
144
  try {
224
- for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
225
- _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
226
- assets = chunkGroup.assets.map(function(asset) {
227
- var filename = asset.name;
228
- return publicPath ? normalizePath(publicPath) + filename : filename;
229
- });
230
- referenceCssAssets = assets.filter(function(asset) {
231
- return /\.css$/.test(asset);
232
- });
233
- routeAssets[name] = {
234
- chunkIds: chunkGroup.chunks,
235
- assets,
236
- referenceCssAssets
237
- };
238
- if (prevManifest.routeAssets[name]) {
239
- mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
240
- if (Array.isArray(obj)) {
241
- return obj.concat(source);
242
- }
243
- return Object.assign(source, obj);
244
- });
245
- }
145
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
146
+ _iterator2.return();
246
147
  }
247
- } catch (err) {
248
- _didIteratorError = true;
249
- _iteratorError = err;
250
148
  } finally {
251
- try {
252
- if (!_iteratorNormalCompletion && _iterator.return != null) {
253
- _iterator.return();
254
- }
255
- } finally {
256
- if (_didIteratorError) {
257
- throw _iteratorError;
258
- }
149
+ if (_didIteratorError2) {
150
+ throw _iteratorError2;
259
151
  }
260
152
  }
261
- manifest = {
262
- routeAssets
263
- };
264
- entryNames = Array.from(compilation.entrypoints.keys());
265
- entryChunks = [];
266
- if (isRspack) {
267
- entryChunks = _this1.getEntryChunks(compilation, chunks);
268
- } else {
269
- orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
270
- var chunk = compilation.namedChunks.get(entryName);
271
- if (chunk) {
272
- return chunk.id;
273
- }
274
- return entryName;
275
- });
276
- entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
277
- return orignalEntryIds.includes(chunk.id);
278
- });
279
- }
280
- entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
281
- entryChunkFileIds = entryChunks.map(function(chunk) {
282
- return chunk.id;
283
- });
284
- for (i = 0; i < entryChunkFiles.length; i++)
285
- _loop(i);
286
- if (prevManifestAsset) {
153
+ }
154
+ var oldHtml = compilation.assets[htmlName];
155
+ var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
156
+ var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
157
+ if (oldHtml) {
158
+ if (enableInlineRouteManifests) {
287
159
  compilation.updateAsset(
288
- ROUTE_MANIFEST_FILE,
289
- new RawSource(JSON.stringify(manifest, null, 2)),
160
+ htmlName,
161
+ new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
290
162
  // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
291
163
  void 0
292
164
  );
293
165
  } else {
294
- compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
166
+ var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
167
+ var scriptUrl = "".concat(publicPath).concat(scriptPath);
168
+ var scriptLoadingAttr = (
169
+ // eslint-disable-next-line no-nested-ternary
170
+ scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : ""
171
+ );
172
+ var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
173
+ compilation.updateAsset(
174
+ htmlName,
175
+ new RawSource(oldHtml.source().toString().replace(placeholder, script)),
176
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
177
+ void 0
178
+ );
179
+ compilation.emitAsset(scriptPath, new RawSource(injectedContent));
295
180
  }
296
- return [
297
- 2
298
- ];
181
+ }
182
+ };
183
+ stats = compilation.getStats().toJson({
184
+ all: false,
185
+ publicPath: true,
186
+ assets: true,
187
+ chunkGroups: true,
188
+ chunks: true,
189
+ ids: true
190
+ });
191
+ publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
192
+ routeAssets = {};
193
+ if (!namedChunkGroups) {
194
+ return [
195
+ 2
196
+ ];
197
+ }
198
+ prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
199
+ prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
200
+ routeAssets: {}
201
+ });
202
+ prevManifest = JSON.parse(prevManifestStr);
203
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
204
+ try {
205
+ for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
206
+ _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
207
+ assets = chunkGroup.assets.map(function(asset) {
208
+ var filename = asset.name;
209
+ return publicPath ? normalizePath(publicPath) + filename : filename;
210
+ });
211
+ referenceCssAssets = assets.filter(function(asset) {
212
+ return /\.css$/.test(asset);
213
+ });
214
+ routeAssets[name] = {
215
+ chunkIds: chunkGroup.chunks,
216
+ assets,
217
+ referenceCssAssets
218
+ };
219
+ if (prevManifest.routeAssets[name]) {
220
+ mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
221
+ if (Array.isArray(obj)) {
222
+ return obj.concat(source);
223
+ }
224
+ return Object.assign(source, obj);
225
+ });
226
+ }
227
+ }
228
+ } catch (err) {
229
+ _didIteratorError = true;
230
+ _iteratorError = err;
231
+ } finally {
232
+ try {
233
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
234
+ _iterator.return();
235
+ }
236
+ } finally {
237
+ if (_didIteratorError) {
238
+ throw _iteratorError;
239
+ }
240
+ }
241
+ }
242
+ manifest = {
243
+ routeAssets
244
+ };
245
+ entryNames = Array.from(compilation.entrypoints.keys());
246
+ entryChunks = [];
247
+ if (isRspack) {
248
+ entryChunks = _this1.getEntryChunks(compilation, chunks);
249
+ } else {
250
+ orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
251
+ var chunk = compilation.namedChunks.get(entryName);
252
+ if (chunk) {
253
+ return chunk.id;
254
+ }
255
+ return entryName;
256
+ });
257
+ entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
258
+ return orignalEntryIds.includes(chunk.id);
299
259
  });
300
- }));
260
+ }
261
+ entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
262
+ entryChunkFileIds = entryChunks.map(function(chunk) {
263
+ return chunk.id;
264
+ });
265
+ for (i = 0; i < entryChunkFiles.length; i++)
266
+ _loop(i);
267
+ if (prevManifestAsset) {
268
+ compilation.updateAsset(
269
+ ROUTE_MANIFEST_FILE,
270
+ new RawSource(JSON.stringify(manifest, null, 2)),
271
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
272
+ void 0
273
+ );
274
+ } else {
275
+ compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
276
+ }
277
+ return [
278
+ 2
279
+ ];
301
280
  });
302
- }
303
- }
304
- ]);
281
+ }));
282
+ });
283
+ };
305
284
  return RouterPlugin2;
306
285
  }();
307
286
  export {
@@ -16,11 +16,12 @@ async function generateBuilder(options, bundlerType) {
16
16
  return builder;
17
17
  }
18
18
  async function applyBuilderPlugins(builder, options) {
19
- const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins");
19
+ const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
20
20
  builder.addPlugins([
21
21
  builderPluginAdapterBasic(),
22
22
  builderPluginAdapterSSR(options),
23
- builderPluginAdapterHtml(options)
23
+ builderPluginAdapterHtml(options),
24
+ builderPluginAdapterWorker()
24
25
  ]);
25
26
  const { normalizedConfig } = options;
26
27
  if (!normalizedConfig.output.disableNodePolyfill) {
@@ -1,5 +1,6 @@
1
1
  import * as path from "path";
2
- import { isHtmlDisabled, mergeRsbuildConfig } from "@rsbuild/shared";
2
+ import { isHtmlDisabled } from "@rsbuild/shared";
3
+ import { mergeRsbuildConfig } from "@rsbuild/core";
3
4
  import { isSSR, fs } from "@modern-js/utils";
4
5
  import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
5
6
  import { getServerCombinedModueFile } from "../../../analyze/utils";
@@ -0,0 +1,25 @@
1
+ import { posix } from "path";
2
+ const getDistPath = (outputConfig, type) => {
3
+ const { distPath } = outputConfig;
4
+ const ret = distPath[type];
5
+ if (typeof ret !== "string") {
6
+ throw new Error(`unknown key ${type} in "output.distPath"`);
7
+ }
8
+ return ret;
9
+ };
10
+ const builderPluginAdapterWorker = () => ({
11
+ name: "builder-plugin-adapter-worker",
12
+ setup(api) {
13
+ api.modifyBundlerChain(async (chain, { isServiceWorker }) => {
14
+ const config = api.getNormalizedConfig();
15
+ if (isServiceWorker) {
16
+ const workerPath = getDistPath(config.output, "worker");
17
+ const filename = posix.join(workerPath, `[name].js`);
18
+ chain.output.filename(filename).chunkFilename(filename).libraryTarget("commonjs2");
19
+ }
20
+ });
21
+ }
22
+ });
23
+ export {
24
+ builderPluginAdapterWorker
25
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./adapterBasic";
2
2
  export * from "./adapterHtml";
3
3
  export * from "./adapterSSR";
4
+ export * from "./adapterWorker";
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  class HtmlAsyncChunkPlugin {
3
2
  apply(compiler) {
4
3
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -22,8 +21,6 @@ class HtmlAsyncChunkPlugin {
22
21
  });
23
22
  }
24
23
  constructor(htmlWebpackPlugin) {
25
- _define_property(this, "name", void 0);
26
- _define_property(this, "htmlWebpackPlugin", void 0);
27
24
  this.name = "HtmlAsyncChunkPlugin";
28
25
  this.htmlWebpackPlugin = htmlWebpackPlugin;
29
26
  }
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  class BottomTemplatePlugin {
3
2
  apply(compiler) {
4
3
  compiler.hooks.compilation.tap(this.name, (compilation) => {
@@ -21,10 +20,8 @@ ${match}`);
21
20
  });
22
21
  }
23
22
  constructor(htmlWebpackPlugin) {
24
- _define_property(this, "htmlWebpackPlugin", void 0);
25
- _define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
26
- _define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
27
- _define_property(this, "name", void 0);
23
+ this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
24
+ this.bodyRegExp = /(<\/\s*body\s*>)/i;
28
25
  this.htmlWebpackPlugin = htmlWebpackPlugin;
29
26
  this.name = "bottom-template";
30
27
  }
@@ -1,4 +1,3 @@
1
- import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
1
  import { createHash } from "crypto";
3
2
  import { mergeWith } from "@modern-js/utils/lodash";
4
3
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
@@ -206,13 +205,7 @@ class RouterPlugin {
206
205
  });
207
206
  }
208
207
  constructor({ staticJsDir = "static/js", HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = "defer", nonce }) {
209
- _define_property(this, "name", "RouterPlugin");
210
- _define_property(this, "HtmlBundlerPlugin", void 0);
211
- _define_property(this, "enableInlineRouteManifests", void 0);
212
- _define_property(this, "staticJsDir", void 0);
213
- _define_property(this, "disableFilenameHash", void 0);
214
- _define_property(this, "scriptLoading", void 0);
215
- _define_property(this, "nonce", void 0);
208
+ this.name = "RouterPlugin";
216
209
  this.HtmlBundlerPlugin = HtmlBundlerPlugin;
217
210
  this.enableInlineRouteManifests = enableInlineRouteManifests;
218
211
  this.staticJsDir = staticJsDir;
@@ -0,0 +1,2 @@
1
+ import { RsbuildPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginAdapterWorker: () => RsbuildPlugin;
@@ -1,3 +1,4 @@
1
1
  export * from './adapterBasic';
2
2
  export * from './adapterHtml';
3
3
  export * from './adapterSSR';
4
+ export * from './adapterWorker';
@@ -1,3 +1,3 @@
1
1
  import type { AppLegacyNormalizedConfig, AppLegacyUserConfig, AppNormalizedConfig, AppUserConfig } from '../../types';
2
2
  export declare function transformNormalizedConfig(config: AppLegacyNormalizedConfig): AppNormalizedConfig<'webpack'>;
3
- export declare function checkIsLegacyConfig(config: AppLegacyUserConfig | AppUserConfig): config is AppLegacyUserConfig;
3
+ export declare function checkIsLegacyConfig(config: AppLegacyUserConfig | AppUserConfig<'shared'>): config is AppLegacyUserConfig;
@@ -4,7 +4,7 @@ import type { AppLegacyUserConfig, AppUserConfig } from './types';
4
4
  * This function helps you to autocomplete configuration types.
5
5
  * It accepts a direct config object, or a function that returns a config.
6
6
  */
7
- export declare const defineConfig: <B extends "rspack" | "webpack" = "webpack">(config: UserConfigExport<AppUserConfig<B_1>>) => UserConfigExport<AppUserConfig<B_1>>;
7
+ export declare const defineConfig: <B extends "rspack" | "webpack" = "webpack">(config: UserConfigExport<AppUserConfig<B>>) => UserConfigExport<AppUserConfig<B>>;
8
8
  /**
9
9
  * @deprecated Please use `defineConfig` instead.
10
10
  * `defineLegacyConfig` will be removed in the future major version.
@@ -1,5 +1,6 @@
1
1
  import type { ServerUserConfig, BffUserConfig } from '@modern-js/server-core';
2
2
  import type { UniBuilderPlugin } from '@modern-js/uni-builder';
3
+ import type { Bundler } from '../utils';
3
4
  import type { OutputUserConfig } from './output';
4
5
  import type { SourceUserConfig } from './source';
5
6
  import type { TestingUserConfig } from './testing';
@@ -17,7 +18,7 @@ export interface RuntimeUserConfig {
17
18
  export interface RuntimeByEntriesUserConfig {
18
19
  [name: string]: RuntimeUserConfig;
19
20
  }
20
- export interface AppToolsUserConfig {
21
+ export interface AppToolsUserConfig<B extends Bundler> {
21
22
  server?: ServerUserConfig;
22
23
  source?: SourceUserConfig;
23
24
  output?: OutputUserConfig;
@@ -33,7 +34,7 @@ export interface AppToolsUserConfig {
33
34
  runtime?: RuntimeUserConfig;
34
35
  runtimeByEntries?: RuntimeByEntriesUserConfig;
35
36
  html?: HtmlUserConfig;
36
- tools?: ToolsUserConfig;
37
+ tools?: ToolsUserConfig<B>;
37
38
  security?: SecurityUserConfig;
38
39
  testing?: TestingUserConfig;
39
40
  builderPlugins?: UniBuilderPlugin[];
@@ -44,4 +45,4 @@ interface SharedNormalizedConfig<RawConfig> {
44
45
  cliOptions?: Record<string, any>;
45
46
  _raw: RawConfig;
46
47
  }
47
- export type AppToolsNormalizedConfig<Config = AppToolsUserConfig> = Required<Config> & SharedNormalizedConfig<Config>;
48
+ export type AppToolsNormalizedConfig<Config = AppToolsUserConfig<'shared'>> = Required<Config> & SharedNormalizedConfig<Config>;
@@ -2,9 +2,10 @@ import type { JestConfig } from '@modern-js/types';
2
2
  import type { PluginSwcOptions } from '@rsbuild/plugin-swc';
3
3
  import type { PluginEsbuildOptions } from '@rsbuild/plugin-esbuild';
4
4
  import type { UniBuilderConfig } from '@modern-js/uni-builder';
5
- import type { UnwrapBuilderConfig } from '../utils';
5
+ import type { UnwrapBuilderConfig, Bundler } from '../utils';
6
6
  export type Tailwindcss = Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
7
- export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, 'tools'> {
7
+ type BuilderToolsConfig = UnwrapBuilderConfig<UniBuilderConfig, 'tools'>;
8
+ export interface ToolsUserConfig<B extends Bundler = 'webpack'> extends Omit<BuilderToolsConfig, 'swc'> {
8
9
  /**
9
10
  * Used to custom Tailwind CSS configurations.
10
11
  * @requires `tailwindcss` plugin.
@@ -25,7 +26,7 @@ export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, '
25
26
  * The configuration of `swc` is provided by `swc` plugin.
26
27
  * Please use `yarn new` or `pnpm new` to enable the corresponding capability.
27
28
  */
28
- swc?: PluginSwcOptions<'outer'>;
29
+ swc?: B extends 'shared' ? undefined : B extends 'webpack' ? PluginSwcOptions<'outer'> : BuilderToolsConfig['swc'];
29
30
  /**
30
31
  * Used to custom Esbuild configurations.
31
32
  * @requires `esbuild` plugin.
@@ -34,3 +35,4 @@ export interface ToolsUserConfig extends UnwrapBuilderConfig<UniBuilderConfig, '
34
35
  */
35
36
  esbuild?: PluginEsbuildOptions;
36
37
  }
38
+ export {};
@@ -12,8 +12,8 @@ export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormal
12
12
  export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig, } from '@modern-js/core';
13
13
  export type AppTools<B extends Bundler = 'webpack'> = {
14
14
  hooks: AppToolsHooks<B>;
15
- userConfig: AppToolsUserConfig;
16
- normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig>;
15
+ userConfig: AppToolsUserConfig<B>;
16
+ normalizedConfig: AppToolsNormalizedConfig<AppToolsUserConfig<'shared'>>;
17
17
  };
18
18
  export type LegacyAppTools = {
19
19
  hooks: AppToolsHooks;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.48.0",
18
+ "version": "2.48.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -69,37 +69,37 @@
69
69
  "@babel/parser": "^7.22.15",
70
70
  "@babel/traverse": "^7.23.2",
71
71
  "@babel/types": "^7.23.0",
72
- "@rsbuild/plugin-esbuild": "0.4.8",
73
- "@rsbuild/plugin-node-polyfill": "0.4.8",
74
- "@rsbuild/shared": "0.4.8",
75
- "@rsbuild/core": "0.4.8",
72
+ "@rsbuild/plugin-esbuild": "0.4.15",
73
+ "@rsbuild/plugin-node-polyfill": "0.4.15",
74
+ "@rsbuild/shared": "0.4.15",
75
+ "@rsbuild/core": "0.4.15",
76
76
  "es-module-lexer": "^1.1.0",
77
77
  "esbuild": "0.17.19",
78
78
  "@swc/helpers": "0.5.3",
79
- "@modern-js/uni-builder": "2.48.0",
80
- "@modern-js/core": "2.48.0",
81
- "@modern-js/node-bundle-require": "2.48.0",
82
- "@modern-js/plugin": "2.48.0",
83
- "@modern-js/plugin-i18n": "2.48.0",
84
- "@modern-js/plugin-data-loader": "2.48.0",
85
- "@modern-js/plugin-lint": "2.48.0",
86
- "@modern-js/server": "2.48.0",
87
- "@modern-js/prod-server": "2.48.0",
88
- "@modern-js/server-utils": "2.48.0",
89
- "@modern-js/types": "2.48.0",
90
- "@modern-js/utils": "2.48.0",
91
- "@modern-js/server-core": "2.48.0"
79
+ "@modern-js/uni-builder": "2.48.1",
80
+ "@modern-js/core": "2.48.1",
81
+ "@modern-js/plugin": "2.48.1",
82
+ "@modern-js/node-bundle-require": "2.48.1",
83
+ "@modern-js/plugin-data-loader": "2.48.1",
84
+ "@modern-js/plugin-lint": "2.48.1",
85
+ "@modern-js/plugin-i18n": "2.48.1",
86
+ "@modern-js/prod-server": "2.48.1",
87
+ "@modern-js/server": "2.48.1",
88
+ "@modern-js/server-utils": "2.48.1",
89
+ "@modern-js/types": "2.48.1",
90
+ "@modern-js/utils": "2.48.1",
91
+ "@modern-js/server-core": "2.48.1"
92
92
  },
93
93
  "devDependencies": {
94
- "@rsbuild/plugin-swc": "0.4.8",
94
+ "@rsbuild/plugin-swc": "0.4.15",
95
95
  "@types/babel__traverse": "7.18.5",
96
96
  "@types/jest": "^29",
97
97
  "@types/node": "^14",
98
98
  "jest": "^29",
99
99
  "typescript": "^5",
100
100
  "webpack": "^5.89.0",
101
- "@scripts/jest-config": "2.48.0",
102
- "@scripts/build": "2.48.0"
101
+ "@scripts/build": "2.48.1",
102
+ "@scripts/jest-config": "2.48.1"
103
103
  },
104
104
  "sideEffects": false,
105
105
  "publishConfig": {