@gravity-ui/app-builder 0.29.3-beta.0 → 0.30.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.
Files changed (64) hide show
  1. package/README.md +138 -0
  2. package/dist/cli.js +17 -22
  3. package/dist/commands/build/build-lib.js +5 -8
  4. package/dist/commands/build/build-service/client.js +3 -6
  5. package/dist/commands/build/build-service/index.js +4 -7
  6. package/dist/commands/build/build-service/server.js +11 -17
  7. package/dist/commands/build/index.js +3 -6
  8. package/dist/commands/dev/client.js +34 -63
  9. package/dist/commands/dev/index.js +26 -47
  10. package/dist/commands/dev/server.js +13 -42
  11. package/dist/common/babel/index.js +1 -4
  12. package/dist/common/babel/ui-preset.d.ts +1 -1
  13. package/dist/common/babel/ui-preset.js +0 -1
  14. package/dist/common/child-process/controllable-script.js +5 -32
  15. package/dist/common/child-process/utils.js +4 -30
  16. package/dist/common/command.js +1 -2
  17. package/dist/common/config.js +36 -45
  18. package/dist/common/env.js +3 -5
  19. package/dist/common/library/babel-plugin-replace-paths.js +2 -4
  20. package/dist/common/library/index.js +66 -95
  21. package/dist/common/logger/colors.js +2 -8
  22. package/dist/common/logger/index.js +17 -24
  23. package/dist/common/logger/log-config.js +3 -6
  24. package/dist/common/logger/pretty-time.js +2 -6
  25. package/dist/common/models/index.d.ts +66 -1
  26. package/dist/common/models/index.js +3 -8
  27. package/dist/common/paths.js +3 -28
  28. package/dist/common/s3-upload/compress.js +8 -12
  29. package/dist/common/s3-upload/create-plugin.js +9 -7
  30. package/dist/common/s3-upload/index.js +3 -9
  31. package/dist/common/s3-upload/s3-client.js +11 -37
  32. package/dist/common/s3-upload/upload.js +9 -38
  33. package/dist/common/s3-upload/webpack-plugin.js +5 -9
  34. package/dist/common/swc/compile.js +9 -12
  35. package/dist/common/swc/index.js +2 -7
  36. package/dist/common/swc/utils.js +6 -13
  37. package/dist/common/swc/watch.js +6 -9
  38. package/dist/common/typescript/compile.js +11 -14
  39. package/dist/common/typescript/diagnostic.js +11 -37
  40. package/dist/common/typescript/transformers.js +3 -29
  41. package/dist/common/typescript/utils.js +8 -18
  42. package/dist/common/typescript/watch.js +10 -13
  43. package/dist/common/utils.d.ts +3 -1
  44. package/dist/common/utils.js +16 -22
  45. package/dist/common/webpack/compile.js +16 -22
  46. package/dist/common/webpack/config.d.ts +0 -2
  47. package/dist/common/webpack/config.js +187 -137
  48. package/dist/common/webpack/node-externals.js +5 -34
  49. package/dist/common/webpack/progress-plugin.js +3 -6
  50. package/dist/common/webpack/public-path.d.ts +0 -1
  51. package/dist/common/webpack/public-path.js +1 -1
  52. package/dist/common/webpack/rspack.js +1 -5
  53. package/dist/common/webpack/runtime-versioning-plugin.d.ts +5 -0
  54. package/dist/common/webpack/runtime-versioning-plugin.js +20 -0
  55. package/dist/common/webpack/storybook.js +21 -53
  56. package/dist/common/webpack/utils.js +9 -36
  57. package/dist/common/webpack/worker/public-path.worker.d.ts +0 -1
  58. package/dist/common/webpack/worker/public-path.worker.js +2 -1
  59. package/dist/common/webpack/worker/worker-loader.js +4 -34
  60. package/dist/create-cli.d.ts +2 -2
  61. package/dist/create-cli.js +19 -48
  62. package/dist/index.d.ts +1 -1
  63. package/dist/index.js +5 -27
  64. package/package.json +9 -6
@@ -1,77 +1,46 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.webpackConfigFactory = webpackConfigFactory;
30
- exports.rspackConfigFactory = rspackConfigFactory;
31
- exports.configureModuleRules = configureModuleRules;
32
- exports.configureResolve = configureResolve;
33
- exports.configureOptimization = configureOptimization;
34
- const path = __importStar(require("node:path"));
35
- const fs = __importStar(require("node:fs"));
36
- const webpack = __importStar(require("webpack"));
37
- const clean_webpack_plugin_1 = require("clean-webpack-plugin");
38
- const webpack_manifest_plugin_1 = require("webpack-manifest-plugin");
39
- const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
40
- const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
41
- const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
42
- const webpack_assets_manifest_1 = __importDefault(require("webpack-assets-manifest"));
43
- const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
44
- const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
45
- const moment_timezone_data_webpack_plugin_1 = __importDefault(require("moment-timezone-data-webpack-plugin"));
46
- const webpack_plugin_1 = __importDefault(require("@statoscope/webpack-plugin"));
47
- const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
48
- const core_1 = require("@rspack/core");
49
- const rspack_1 = require("./rspack");
50
- const ts_checker_rspack_plugin_1 = require("ts-checker-rspack-plugin");
51
- const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
52
- const paths_1 = __importDefault(require("../paths"));
53
- const babel_1 = require("../babel");
54
- const progress_plugin_1 = require("./progress-plugin");
55
- const utils_1 = require("./utils");
56
- const s3_upload_1 = require("../s3-upload");
57
- const log_config_1 = require("../logger/log-config");
58
- const utils_2 = require("../typescript/utils");
59
- const node_externals_1 = require("./node-externals");
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+ import * as webpack from 'webpack';
4
+ import { CleanWebpackPlugin } from 'clean-webpack-plugin';
5
+ import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
6
+ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
7
+ import MiniCSSExtractPlugin from 'mini-css-extract-plugin';
8
+ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
9
+ import WebpackAssetsManifest from 'webpack-assets-manifest';
10
+ import { RspackManifestPlugin } from 'rspack-manifest-plugin';
11
+ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
12
+ import MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin';
13
+ import StatoscopeWebpackPlugin from '@statoscope/webpack-plugin';
14
+ import CircularDependencyPlugin from 'circular-dependency-plugin';
15
+ import { rspack } from '@rspack/core';
16
+ import { generateAssetsManifest } from './rspack';
17
+ import { TsCheckerRspackPlugin } from 'ts-checker-rspack-plugin';
18
+ import ReactRefreshRspackPlugin from '@rspack/plugin-react-refresh';
19
+ import paths from '../paths';
20
+ import { babelPreset } from '../babel';
21
+ import { createProgressPlugin } from './progress-plugin';
22
+ import { resolveTsConfigPathsToAlias } from './utils';
23
+ import { createS3UploadPlugins } from '../s3-upload';
24
+ import { logConfig } from '../logger/log-config';
25
+ import { resolveTypescript } from '../typescript/utils';
26
+ import { nodeExternals } from './node-externals';
60
27
  const imagesSizeLimit = 2048;
61
28
  const fontSizeLimit = 8192;
62
29
  function getHelperOptions({ webpackMode, config, logger, isSsr = false, configPath, }) {
63
30
  const isEnvDevelopment = webpackMode === "development" /* WebpackMode.Dev */;
64
31
  const isEnvProduction = webpackMode === "production" /* WebpackMode.Prod */;
32
+ let buildDirectory = config.outputPath || (isSsr ? paths.appSsrBuild : paths.appBuild);
33
+ if (config.moduleFederation) {
34
+ buildDirectory = path.resolve(buildDirectory, config.moduleFederation.name);
35
+ }
65
36
  return {
66
37
  config,
67
38
  logger,
68
39
  isEnvDevelopment,
69
40
  isEnvProduction,
70
41
  configType: webpackMode,
71
- buildDirectory: config.outputPath || (isSsr ? paths_1.default.appSsrBuild : paths_1.default.appBuild),
72
- assetsManifestFile: config.assetsManifestFile,
73
- entry: config.entry,
74
- entriesDirectory: isSsr ? paths_1.default.appSsrEntry : paths_1.default.appEntry,
42
+ buildDirectory,
43
+ entriesDirectory: isSsr ? paths.appSsrEntry : paths.appEntry,
75
44
  isSsr,
76
45
  configPath,
77
46
  };
@@ -82,7 +51,7 @@ function configureExternals({ config, isSsr }) {
82
51
  externals =
83
52
  config.ssr?.noExternal === true
84
53
  ? undefined
85
- : (0, node_externals_1.nodeExternals)({
54
+ : nodeExternals({
86
55
  noExternal: config.ssr?.noExternal,
87
56
  module: config.ssr?.moduleType === 'esm',
88
57
  });
@@ -91,21 +60,29 @@ function configureExternals({ config, isSsr }) {
91
60
  }
92
61
  function configureWebpackCache(options) {
93
62
  const { config } = options;
94
- if (typeof config.cache === 'object' && config.cache.type === 'filesystem') {
95
- return {
96
- ...config.cache,
63
+ let cache = config.cache;
64
+ if (typeof cache === 'object' && cache.type === 'filesystem') {
65
+ cache = {
66
+ ...cache,
97
67
  buildDependencies: getCacheBuildDependencies(options),
98
68
  };
69
+ if (config.moduleFederation) {
70
+ cache = {
71
+ name: config.moduleFederation.name,
72
+ version: config.moduleFederation.version,
73
+ ...cache,
74
+ };
75
+ }
99
76
  }
100
- return config.cache;
77
+ return cache;
101
78
  }
102
- async function webpackConfigFactory(options) {
79
+ export async function webpackConfigFactory(options) {
103
80
  const { config } = options;
104
81
  const helperOptions = getHelperOptions(options);
105
82
  const { isSsr, isEnvProduction } = helperOptions;
106
83
  let webpackConfig = {
107
84
  mode: isEnvProduction ? 'production' : 'development',
108
- context: paths_1.default.app,
85
+ context: paths.app,
109
86
  bail: isEnvProduction,
110
87
  target: isSsr ? 'node' : undefined,
111
88
  devtool: configureDevTool(helperOptions),
@@ -138,11 +115,11 @@ async function webpackConfigFactory(options) {
138
115
  isSsr,
139
116
  });
140
117
  if (config.debugWebpack) {
141
- (0, log_config_1.logConfig)('Preview webpack config', webpackConfig);
118
+ logConfig('Preview webpack config', webpackConfig);
142
119
  }
143
120
  return webpackConfig;
144
121
  }
145
- async function rspackConfigFactory(options) {
122
+ export async function rspackConfigFactory(options) {
146
123
  const { config } = options;
147
124
  const helperOptions = getHelperOptions(options);
148
125
  const { isSsr, isEnvProduction, isEnvDevelopment } = helperOptions;
@@ -150,7 +127,7 @@ async function rspackConfigFactory(options) {
150
127
  const cache = Boolean(config.cache) || (isEnvDevelopment && Boolean(config.lazyCompilation));
151
128
  let rspackConfig = {
152
129
  mode: isEnvProduction ? 'production' : 'development',
153
- context: paths_1.default.app,
130
+ context: paths.app,
154
131
  bail: isEnvProduction,
155
132
  target: isSsr ? 'node' : undefined,
156
133
  devtool: configureDevTool(helperOptions),
@@ -180,11 +157,11 @@ async function rspackConfigFactory(options) {
180
157
  isSsr,
181
158
  });
182
159
  if (config.debugWebpack) {
183
- (0, log_config_1.logConfig)('Preview rspack config', rspackConfig);
160
+ logConfig('Preview rspack config', rspackConfig);
184
161
  }
185
162
  return rspackConfig;
186
163
  }
187
- async function configureModuleRules(helperOptions, additionalRules = []) {
164
+ export async function configureModuleRules(helperOptions, additionalRules = []) {
188
165
  const jsLoader = await createJavaScriptLoader(helperOptions);
189
166
  return [
190
167
  ...createSourceMapRules(!helperOptions.config.disableSourceMapGeneration),
@@ -225,10 +202,10 @@ function getCacheBuildDependencies({ config, configPath }) {
225
202
  const buildDependencies = {};
226
203
  const dependenciesGroups = {
227
204
  appBuilderConfig: configPath ? [configPath] : [],
228
- packageJson: [path.join(paths_1.default.app, 'package.json')],
205
+ packageJson: [path.join(paths.app, 'package.json')],
229
206
  tsconfig: [
230
- path.join(paths_1.default.app, 'tsconfig.json'),
231
- path.join(paths_1.default.appClient, 'tsconfig.json'),
207
+ path.join(paths.app, 'tsconfig.json'),
208
+ path.join(paths.appClient, 'tsconfig.json'),
232
209
  ],
233
210
  };
234
211
  for (const [group, filePaths] of Object.entries(dependenciesGroups)) {
@@ -319,16 +296,16 @@ function configureRspackExperiments(options) {
319
296
  lazyCompilation,
320
297
  };
321
298
  }
322
- function configureResolve({ isEnvProduction, config }) {
299
+ export function configureResolve({ isEnvProduction, config }) {
323
300
  const alias = { ...config.alias };
324
301
  for (const [key, value] of Object.entries(alias)) {
325
- alias[key] = path.resolve(paths_1.default.app, value);
302
+ alias[key] = path.resolve(paths.app, value);
326
303
  }
327
304
  if (isEnvProduction && config.reactProfiling) {
328
305
  alias['react-dom$'] = 'react-dom/profiling';
329
306
  alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
330
307
  }
331
- const { aliases, modules = [] } = (0, utils_1.resolveTsConfigPathsToAlias)(paths_1.default.appClient);
308
+ const { aliases, modules = [] } = resolveTsConfigPathsToAlias(paths.appClient);
332
309
  return {
333
310
  alias: {
334
311
  ...aliases,
@@ -340,6 +317,10 @@ function configureResolve({ isEnvProduction, config }) {
340
317
  fallback: config.fallback,
341
318
  };
342
319
  }
320
+ function isModuleFederationEntry(entryName, fileName) {
321
+ // Ignore bootstrap file for module federation entries
322
+ return entryName === fileName || `${entryName}-bootstrap` === fileName;
323
+ }
343
324
  function createEntryArray(entry) {
344
325
  if (typeof entry === 'string') {
345
326
  return [require.resolve('./public-path'), entry];
@@ -352,24 +333,44 @@ function addEntry(entry, file) {
352
333
  [path.parse(file).name]: createEntryArray(file),
353
334
  };
354
335
  }
355
- function configureEntry({ config, entry, entriesDirectory }) {
356
- if (typeof entry === 'string' || Array.isArray(entry)) {
357
- return createEntryArray(entry);
336
+ function configureEntry({ config, entriesDirectory }) {
337
+ if (typeof config.entry === 'string' || Array.isArray(config.entry)) {
338
+ return createEntryArray(config.entry);
358
339
  }
359
- if (typeof entry === 'object') {
360
- return Object.entries(entry).reduce((acc, [key, value]) => ({
340
+ if (typeof config.entry === 'object') {
341
+ return Object.entries(config.entry).reduce((acc, [key, value]) => ({
361
342
  ...acc,
362
343
  [key]: createEntryArray(value),
363
344
  }), {});
364
345
  }
365
- let entries = fs.readdirSync(entriesDirectory).filter((file) => /\.[jt]sx?$/.test(file));
346
+ let entryFiles = fs.readdirSync(entriesDirectory).filter((file) => /\.[jt]sx?$/.test(file));
347
+ let result = {};
348
+ if (config.moduleFederation) {
349
+ const { name, remotes } = config.moduleFederation;
350
+ const entryFile = entryFiles.find((item) => path.parse(item).name === name);
351
+ if (!entryFile) {
352
+ throw new Error(`Entry "${name}" not found`);
353
+ }
354
+ // If remotes are not defined, it means that we are a remote
355
+ if (!remotes) {
356
+ return path.resolve(entriesDirectory, entryFile);
357
+ }
358
+ entryFiles = entryFiles.filter((file) => {
359
+ const fileName = path.parse(file).name;
360
+ return (!isModuleFederationEntry(name, fileName) &&
361
+ remotes.every((remote) => !isModuleFederationEntry(remote, fileName)));
362
+ });
363
+ result = {
364
+ main: createEntryArray(path.resolve(entriesDirectory, entryFile)),
365
+ };
366
+ }
366
367
  if (Array.isArray(config.entryFilter) && config.entryFilter.length) {
367
- entries = entries.filter((file) => config.entryFilter?.includes(file.split('.')[0] ?? ''));
368
+ entryFiles = entryFiles.filter((file) => config.entryFilter?.includes(path.parse(file).name));
368
369
  }
369
- if (!entries.length) {
370
+ if (!entryFiles.length) {
370
371
  throw new Error('No entries were found after applying entry filter');
371
372
  }
372
- return entries.reduce((acc, file) => addEntry(acc, path.resolve(entriesDirectory, file)), {});
373
+ return entryFiles.reduce((acc, file) => addEntry(acc, path.resolve(entriesDirectory, file)), result);
373
374
  }
374
375
  function getFileNames({ isEnvProduction, isSsr, config }) {
375
376
  let ext = 'js';
@@ -384,18 +385,25 @@ function getFileNames({ isEnvProduction, isSsr, config }) {
384
385
  };
385
386
  }
386
387
  function configureOutput(options) {
387
- let ssrOptions;
388
+ let ssrOptions, moduleFederationOptions;
388
389
  if (options.isSsr) {
389
390
  ssrOptions = {
390
391
  library: { type: options.config.ssr?.moduleType === 'esm' ? 'module' : 'commonjs2' },
391
392
  chunkFormat: false,
392
393
  };
393
394
  }
395
+ if (options.config.moduleFederation) {
396
+ moduleFederationOptions = {
397
+ publicPath: 'auto',
398
+ uniqueName: options.config.moduleFederation.name,
399
+ };
400
+ }
394
401
  return {
395
402
  ...getFileNames(options),
396
403
  path: options.buildDirectory,
397
404
  pathinfo: options.isEnvDevelopment,
398
405
  ...ssrOptions,
406
+ ...moduleFederationOptions,
399
407
  };
400
408
  }
401
409
  async function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, isSsr, }) {
@@ -493,7 +501,7 @@ async function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, confi
493
501
  }
494
502
  }
495
503
  const babelTransformOptions = await config.babel({
496
- presets: [(0, babel_1.babelPreset)({ newJsxTransform: config.newJsxTransform, isSsr })],
504
+ presets: [babelPreset({ newJsxTransform: config.newJsxTransform, isSsr })],
497
505
  plugins,
498
506
  }, { configType, isSsr });
499
507
  return {
@@ -512,9 +520,9 @@ async function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, confi
512
520
  }
513
521
  function createJavaScriptRule({ config, isEnvProduction }, jsLoader) {
514
522
  const include = [
515
- paths_1.default.appClient,
523
+ paths.appClient,
516
524
  ...(config.monaco && isEnvProduction
517
- ? [path.resolve(paths_1.default.appNodeModules, 'monaco-editor/esm/vs')]
525
+ ? [path.resolve(paths.appNodeModules, 'monaco-editor/esm/vs')]
518
526
  : []),
519
527
  ...(config.includes || []),
520
528
  ];
@@ -571,7 +579,7 @@ function createSassStylesRule(options) {
571
579
  options: {
572
580
  sourceMap: true, // must be always true for work with resolve-url-loader
573
581
  sassOptions: {
574
- loadPaths: [paths_1.default.appClient],
582
+ loadPaths: [paths.appClient],
575
583
  },
576
584
  },
577
585
  },
@@ -594,15 +602,27 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
594
602
  const isRspack = config.bundler === 'rspack';
595
603
  const loaders = [];
596
604
  if (!config.transformCssWithLightningCss) {
605
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
606
+ const postcssPlugins = [
607
+ [require.resolve('postcss-preset-env'), { enableClientSidePolyfills: false }],
608
+ ];
609
+ if (config.moduleFederation?.isolateStyles) {
610
+ const { name, isolateStyles } = config.moduleFederation;
611
+ postcssPlugins.push([
612
+ require.resolve('postcss-prefix-selector'),
613
+ {
614
+ prefix: isolateStyles.getPrefix(name),
615
+ transform: isolateStyles.prefixSelector,
616
+ },
617
+ ]);
618
+ }
597
619
  loaders.push({
598
620
  loader: require.resolve('postcss-loader'),
599
621
  options: {
600
622
  sourceMap: !config.disableSourceMapGeneration,
601
623
  postcssOptions: {
602
624
  config: false,
603
- plugins: [
604
- [require.resolve('postcss-preset-env'), { enableClientSidePolyfills: false }],
605
- ],
625
+ plugins: postcssPlugins,
606
626
  },
607
627
  },
608
628
  });
@@ -632,7 +652,7 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
632
652
  });
633
653
  if (isEnvProduction) {
634
654
  loaders.unshift({
635
- loader: isRspack ? core_1.rspack.CssExtractRspackPlugin.loader : mini_css_extract_plugin_1.default.loader,
655
+ loader: isRspack ? rspack.CssExtractRspackPlugin.loader : MiniCSSExtractPlugin.loader,
636
656
  options: { emit: !isSsr },
637
657
  });
638
658
  }
@@ -640,8 +660,8 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
640
660
  if (isSsr || config.ssr) {
641
661
  loaders.unshift({
642
662
  loader: isRspack
643
- ? core_1.rspack.CssExtractRspackPlugin.loader
644
- : mini_css_extract_plugin_1.default.loader,
663
+ ? rspack.CssExtractRspackPlugin.loader
664
+ : MiniCSSExtractPlugin.loader,
645
665
  options: { emit: !isSsr },
646
666
  });
647
667
  }
@@ -699,7 +719,7 @@ function createIconsRule({ isEnvProduction, config, isSsr }, jsLoader) {
699
719
  function createAssetsRules({ isEnvProduction, config, isSsr }) {
700
720
  const imagesRule = {
701
721
  test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
702
- include: [paths_1.default.appClient, ...(config.images || [])],
722
+ include: [paths.appClient, ...(config.images || [])],
703
723
  type: 'asset',
704
724
  parser: {
705
725
  dataUrlCondition: {
@@ -713,7 +733,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
713
733
  };
714
734
  const fontsRule = {
715
735
  test: /\.(ttf|eot|woff2?)$/,
716
- include: [paths_1.default.appClient],
736
+ include: [paths.appClient],
717
737
  type: 'asset',
718
738
  parser: {
719
739
  dataUrlCondition: {
@@ -732,7 +752,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
732
752
  rules.unshift({
733
753
  test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
734
754
  issuer: /\.s?css$/,
735
- include: [paths_1.default.appClient, ...(config.images || [])],
755
+ include: [paths.appClient, ...(config.images || [])],
736
756
  type: 'asset',
737
757
  parser: {
738
758
  dataUrlCondition: {
@@ -747,7 +767,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
747
767
  }, {
748
768
  test: /\.(ttf|eot|woff2?)$/,
749
769
  issuer: /\.s?css$/,
750
- include: [paths_1.default.appClient],
770
+ include: [paths.appClient],
751
771
  type: 'asset',
752
772
  parser: {
753
773
  dataUrlCondition: {
@@ -796,7 +816,7 @@ function createMomentTimezoneDataPlugin(options = {}) {
796
816
  // https://momentjs.com/timezone/docs/#/use-it/webpack/
797
817
  const startYear = options.startYear ?? currentYear;
798
818
  const endYear = options.endYear ?? currentYear;
799
- return new moment_timezone_data_webpack_plugin_1.default({ ...options, startYear, endYear });
819
+ return new MomentTimezoneDataPlugin({ ...options, startYear, endYear });
800
820
  }
801
821
  function getDefinitions({ config, isSsr }) {
802
822
  return {
@@ -836,8 +856,8 @@ function getForkTsCheckerOptions({ config, }) {
836
856
  : {
837
857
  ...config.forkTsChecker,
838
858
  typescript: {
839
- typescriptPath: (0, utils_2.resolveTypescript)(),
840
- configFile: path.resolve(paths_1.default.appClient, 'tsconfig.json'),
859
+ typescriptPath: resolveTypescript(),
860
+ configFile: path.resolve(paths.appClient, 'tsconfig.json'),
841
861
  diagnosticOptions: {
842
862
  syntactic: true,
843
863
  },
@@ -860,7 +880,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
860
880
  const excludeFromClean = config.excludeFromClean || [];
861
881
  const forkTsCheckerOptions = getForkTsCheckerOptions(options);
862
882
  const plugins = [
863
- new clean_webpack_plugin_1.CleanWebpackPlugin({
883
+ new CleanWebpackPlugin({
864
884
  verbose: config.verbose,
865
885
  cleanOnceBeforeBuildPatterns: [
866
886
  '**/*',
@@ -884,7 +904,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
884
904
  if (typeof config.detectCircularDependencies === 'object') {
885
905
  circularPluginOptions = config.detectCircularDependencies;
886
906
  }
887
- plugins.push(new circular_dependency_plugin_1.default(circularPluginOptions));
907
+ plugins.push(new CircularDependencyPlugin(circularPluginOptions));
888
908
  }
889
909
  if (isEnvProduction || isSsr || config.ssr) {
890
910
  plugins.push(new bundlerPlugins.CSSExtractPlugin(getCssExtractPluginOptions(options)));
@@ -908,10 +928,36 @@ function configureCommonPlugins(options, bundlerPlugins) {
908
928
  }));
909
929
  }
910
930
  plugins.push(createMomentTimezoneDataPlugin(config.momentTz));
931
+ if (config.moduleFederation) {
932
+ const { name, version, publicPath, remotes, originalRemotes, remotesRuntimeVersioning, runtimePlugins, ...restOptions } = config.moduleFederation;
933
+ let actualRemotes = originalRemotes;
934
+ if (remotes) {
935
+ actualRemotes = remotes.reduce((acc, remoteName) => {
936
+ const remoteFilename = remotesRuntimeVersioning
937
+ ? 'entry-[version].js'
938
+ : 'entry.js';
939
+ // eslint-disable-next-line no-param-reassign
940
+ acc[remoteName] =
941
+ `${remoteName}@${publicPath}${remoteName}/${remoteFilename}`;
942
+ return acc;
943
+ }, {});
944
+ }
945
+ const actualRuntimePlugins = runtimePlugins || [];
946
+ if (remotesRuntimeVersioning) {
947
+ actualRuntimePlugins.push(require.resolve('./runtime-versioning-plugin'));
948
+ }
949
+ plugins.push(new bundlerPlugins.ModuleFederationPlugin({
950
+ name,
951
+ filename: version ? `entry-${version}.js` : 'entry.js',
952
+ remotes: actualRemotes,
953
+ runtimePlugins: actualRuntimePlugins,
954
+ ...restOptions,
955
+ }));
956
+ }
911
957
  }
912
958
  if (isEnvProduction) {
913
959
  if (config.analyzeBundle === 'true') {
914
- plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
960
+ plugins.push(new BundleAnalyzerPlugin({
915
961
  openAnalyzer: false,
916
962
  analyzerMode: 'static',
917
963
  reportFilename: 'stats.html',
@@ -919,7 +965,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
919
965
  }
920
966
  if (config.analyzeBundle === 'statoscope') {
921
967
  const customStatoscopeConfig = config.statoscopeConfig || {};
922
- plugins.push(new webpack_plugin_1.default({
968
+ plugins.push(new StatoscopeWebpackPlugin({
923
969
  saveReportTo: path.resolve(options.buildDirectory, 'report.html'),
924
970
  saveStatsTo: path.resolve(options.buildDirectory, 'stats.json'),
925
971
  open: false,
@@ -940,7 +986,7 @@ function configureCommonPlugins(options, bundlerPlugins) {
940
986
  }
941
987
  }
942
988
  if (config.cdn) {
943
- plugins.push(...(0, s3_upload_1.createS3UploadPlugins)(config, options.logger));
989
+ plugins.push(...createS3UploadPlugins(config, options.logger));
944
990
  }
945
991
  return plugins;
946
992
  }
@@ -950,23 +996,25 @@ function configureWebpackPlugins(options) {
950
996
  DefinePlugin: webpack.DefinePlugin,
951
997
  ContextReplacementPlugin: webpack.ContextReplacementPlugin,
952
998
  ProvidePlugin: webpack.ProvidePlugin,
953
- ProgressPlugin: (0, progress_plugin_1.createProgressPlugin)(webpack.ProgressPlugin),
954
- ManifestPlugin: webpack_manifest_plugin_1.WebpackManifestPlugin,
955
- TsCheckerPlugin: fork_ts_checker_webpack_plugin_1.default,
956
- CSSExtractPlugin: mini_css_extract_plugin_1.default,
999
+ ProgressPlugin: createProgressPlugin(webpack.ProgressPlugin),
1000
+ ManifestPlugin: WebpackManifestPlugin,
1001
+ TsCheckerPlugin: ForkTsCheckerWebpackPlugin,
1002
+ CSSExtractPlugin: MiniCSSExtractPlugin,
957
1003
  RSDoctorPlugin: require('@rsdoctor/webpack-plugin').RsdoctorWebpackPlugin,
1004
+ ModuleFederationPlugin: require('@module-federation/enhanced/webpack')
1005
+ .ModuleFederationPlugin,
958
1006
  };
959
1007
  const webpackPlugins = [
960
1008
  ...configureCommonPlugins(options, plugins),
961
- new webpack_assets_manifest_1.default(isEnvProduction
1009
+ new WebpackAssetsManifest(isEnvProduction
962
1010
  ? {
963
1011
  entrypoints: true,
964
- output: options.assetsManifestFile,
1012
+ output: config.assetsManifestFile,
965
1013
  }
966
1014
  : {
967
1015
  entrypoints: true,
968
1016
  writeToDisk: true,
969
- output: path.resolve(options.buildDirectory, options.assetsManifestFile),
1017
+ output: path.resolve(options.buildDirectory, config.assetsManifestFile),
970
1018
  }),
971
1019
  ...(process.env.WEBPACK_PROFILE === 'true' ? [new webpack.debug.ProfilingPlugin()] : []),
972
1020
  ];
@@ -976,32 +1024,34 @@ function configureWebpackPlugins(options) {
976
1024
  overlay: { sockPath: webSocketPath },
977
1025
  exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
978
1026
  });
979
- webpackPlugins.push(new react_refresh_webpack_plugin_1.default(reactRefreshConfig));
1027
+ webpackPlugins.push(new ReactRefreshWebpackPlugin(reactRefreshConfig));
980
1028
  }
981
1029
  return webpackPlugins;
982
1030
  }
983
1031
  function configureRspackPlugins(options) {
984
1032
  const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
985
1033
  const plugins = {
986
- DefinePlugin: core_1.rspack.DefinePlugin,
987
- ContextReplacementPlugin: core_1.rspack.ContextReplacementPlugin,
988
- ProvidePlugin: core_1.rspack.ProvidePlugin,
989
- ProgressPlugin: (0, progress_plugin_1.createProgressPlugin)(core_1.rspack.ProgressPlugin),
990
- ManifestPlugin: rspack_manifest_plugin_1.RspackManifestPlugin,
991
- TsCheckerPlugin: ts_checker_rspack_plugin_1.TsCheckerRspackPlugin,
992
- CSSExtractPlugin: core_1.rspack.CssExtractRspackPlugin,
1034
+ DefinePlugin: rspack.DefinePlugin,
1035
+ ContextReplacementPlugin: rspack.ContextReplacementPlugin,
1036
+ ProvidePlugin: rspack.ProvidePlugin,
1037
+ ProgressPlugin: createProgressPlugin(rspack.ProgressPlugin),
1038
+ ManifestPlugin: RspackManifestPlugin,
1039
+ TsCheckerPlugin: TsCheckerRspackPlugin,
1040
+ CSSExtractPlugin: rspack.CssExtractRspackPlugin,
993
1041
  RSDoctorPlugin: require('@rsdoctor/rspack-plugin').RsdoctorRspackPlugin,
1042
+ ModuleFederationPlugin: require('@module-federation/enhanced/rspack')
1043
+ .ModuleFederationPlugin,
994
1044
  };
995
1045
  const rspackPlugins = [
996
1046
  ...configureCommonPlugins(options, plugins),
997
- new rspack_manifest_plugin_1.RspackManifestPlugin({
1047
+ new RspackManifestPlugin({
998
1048
  fileName: isEnvProduction
999
- ? options.assetsManifestFile
1000
- : path.resolve(options.buildDirectory, options.assetsManifestFile),
1049
+ ? config.assetsManifestFile
1050
+ : path.resolve(options.buildDirectory, config.assetsManifestFile),
1001
1051
  writeToFileEmit: true,
1002
1052
  useLegacyEmit: true,
1003
1053
  publicPath: '',
1004
- generate: rspack_1.generateAssetsManifest,
1054
+ generate: generateAssetsManifest,
1005
1055
  }),
1006
1056
  ];
1007
1057
  if (!isSsr && isEnvDevelopment && config.reactRefresh !== false) {
@@ -1010,7 +1060,7 @@ function configureRspackPlugins(options) {
1010
1060
  overlay: { sockPath: webSocketPath },
1011
1061
  exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
1012
1062
  });
1013
- rspackPlugins.push(new plugin_react_refresh_1.default({
1063
+ rspackPlugins.push(new ReactRefreshRspackPlugin({
1014
1064
  ...reactRefreshConfig,
1015
1065
  overlay: typeof overlay === 'object'
1016
1066
  ? {
@@ -1071,7 +1121,7 @@ function getOptimizationSplitChunks({ config }) {
1071
1121
  },
1072
1122
  };
1073
1123
  }
1074
- function configureOptimization(helperOptions) {
1124
+ export function configureOptimization(helperOptions) {
1075
1125
  const { config, isSsr } = helperOptions;
1076
1126
  if (isSsr) {
1077
1127
  return {};
@@ -1151,7 +1201,7 @@ function configureRspackOptimization(helperOptions) {
1151
1201
  if (typeof lightningCssMinimizerOptions === 'function') {
1152
1202
  lightningCssMinifyOptions = lightningCssMinimizerOptions(lightningCssMinifyOptions);
1153
1203
  }
1154
- cssMinimizer = new core_1.rspack.LightningCssMinimizerRspackPlugin(lightningCssMinifyOptions);
1204
+ cssMinimizer = new rspack.LightningCssMinimizerRspackPlugin(lightningCssMinifyOptions);
1155
1205
  }
1156
1206
  else {
1157
1207
  const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
@@ -1183,8 +1233,8 @@ function configureRspackOptimization(helperOptions) {
1183
1233
  }
1184
1234
  const optimization = {
1185
1235
  splitChunks: getOptimizationSplitChunks(helperOptions),
1186
- runtimeChunk: 'single',
1187
- minimizer: [new core_1.rspack.SwcJsMinimizerRspackPlugin(swcMinifyOptions), cssMinimizer],
1236
+ runtimeChunk: helperOptions.config.moduleFederation ? false : 'single',
1237
+ minimizer: [new rspack.SwcJsMinimizerRspackPlugin(swcMinifyOptions), cssMinimizer],
1188
1238
  };
1189
1239
  return optimization;
1190
1240
  }