@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.
- package/README.md +138 -0
- package/dist/cli.js +17 -22
- package/dist/commands/build/build-lib.js +5 -8
- package/dist/commands/build/build-service/client.js +3 -6
- package/dist/commands/build/build-service/index.js +4 -7
- package/dist/commands/build/build-service/server.js +11 -17
- package/dist/commands/build/index.js +3 -6
- package/dist/commands/dev/client.js +34 -63
- package/dist/commands/dev/index.js +26 -47
- package/dist/commands/dev/server.js +13 -42
- package/dist/common/babel/index.js +1 -4
- package/dist/common/babel/ui-preset.d.ts +1 -1
- package/dist/common/babel/ui-preset.js +0 -1
- package/dist/common/child-process/controllable-script.js +5 -32
- package/dist/common/child-process/utils.js +4 -30
- package/dist/common/command.js +1 -2
- package/dist/common/config.js +36 -45
- package/dist/common/env.js +3 -5
- package/dist/common/library/babel-plugin-replace-paths.js +2 -4
- package/dist/common/library/index.js +66 -95
- package/dist/common/logger/colors.js +2 -8
- package/dist/common/logger/index.js +17 -24
- package/dist/common/logger/log-config.js +3 -6
- package/dist/common/logger/pretty-time.js +2 -6
- package/dist/common/models/index.d.ts +66 -1
- package/dist/common/models/index.js +3 -8
- package/dist/common/paths.js +3 -28
- package/dist/common/s3-upload/compress.js +8 -12
- package/dist/common/s3-upload/create-plugin.js +9 -7
- package/dist/common/s3-upload/index.js +3 -9
- package/dist/common/s3-upload/s3-client.js +11 -37
- package/dist/common/s3-upload/upload.js +9 -38
- package/dist/common/s3-upload/webpack-plugin.js +5 -9
- package/dist/common/swc/compile.js +9 -12
- package/dist/common/swc/index.js +2 -7
- package/dist/common/swc/utils.js +6 -13
- package/dist/common/swc/watch.js +6 -9
- package/dist/common/typescript/compile.js +11 -14
- package/dist/common/typescript/diagnostic.js +11 -37
- package/dist/common/typescript/transformers.js +3 -29
- package/dist/common/typescript/utils.js +8 -18
- package/dist/common/typescript/watch.js +10 -13
- package/dist/common/utils.d.ts +3 -1
- package/dist/common/utils.js +16 -22
- package/dist/common/webpack/compile.js +16 -22
- package/dist/common/webpack/config.d.ts +0 -2
- package/dist/common/webpack/config.js +187 -137
- package/dist/common/webpack/node-externals.js +5 -34
- package/dist/common/webpack/progress-plugin.js +3 -6
- package/dist/common/webpack/public-path.d.ts +0 -1
- package/dist/common/webpack/public-path.js +1 -1
- package/dist/common/webpack/rspack.js +1 -5
- package/dist/common/webpack/runtime-versioning-plugin.d.ts +5 -0
- package/dist/common/webpack/runtime-versioning-plugin.js +20 -0
- package/dist/common/webpack/storybook.js +21 -53
- package/dist/common/webpack/utils.js +9 -36
- package/dist/common/webpack/worker/public-path.worker.d.ts +0 -1
- package/dist/common/webpack/worker/public-path.worker.js +2 -1
- package/dist/common/webpack/worker/worker-loader.js +4 -34
- package/dist/create-cli.d.ts +2 -2
- package/dist/create-cli.js +19 -48
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -27
- package/package.json +9 -6
|
@@ -1,77 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
72
|
-
|
|
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
|
-
:
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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(
|
|
205
|
+
packageJson: [path.join(paths.app, 'package.json')],
|
|
229
206
|
tsconfig: [
|
|
230
|
-
path.join(
|
|
231
|
-
path.join(
|
|
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(
|
|
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 = [] } =
|
|
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,
|
|
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
|
|
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
|
-
|
|
368
|
+
entryFiles = entryFiles.filter((file) => config.entryFilter?.includes(path.parse(file).name));
|
|
368
369
|
}
|
|
369
|
-
if (!
|
|
370
|
+
if (!entryFiles.length) {
|
|
370
371
|
throw new Error('No entries were found after applying entry filter');
|
|
371
372
|
}
|
|
372
|
-
return
|
|
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: [
|
|
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
|
-
|
|
523
|
+
paths.appClient,
|
|
516
524
|
...(config.monaco && isEnvProduction
|
|
517
|
-
? [path.resolve(
|
|
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: [
|
|
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 ?
|
|
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
|
-
?
|
|
644
|
-
:
|
|
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: [
|
|
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: [
|
|
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: [
|
|
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: [
|
|
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
|
|
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:
|
|
840
|
-
configFile: path.resolve(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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(...
|
|
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:
|
|
954
|
-
ManifestPlugin:
|
|
955
|
-
TsCheckerPlugin:
|
|
956
|
-
CSSExtractPlugin:
|
|
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
|
|
1009
|
+
new WebpackAssetsManifest(isEnvProduction
|
|
962
1010
|
? {
|
|
963
1011
|
entrypoints: true,
|
|
964
|
-
output:
|
|
1012
|
+
output: config.assetsManifestFile,
|
|
965
1013
|
}
|
|
966
1014
|
: {
|
|
967
1015
|
entrypoints: true,
|
|
968
1016
|
writeToDisk: true,
|
|
969
|
-
output: path.resolve(options.buildDirectory,
|
|
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
|
|
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:
|
|
987
|
-
ContextReplacementPlugin:
|
|
988
|
-
ProvidePlugin:
|
|
989
|
-
ProgressPlugin:
|
|
990
|
-
ManifestPlugin:
|
|
991
|
-
TsCheckerPlugin:
|
|
992
|
-
CSSExtractPlugin:
|
|
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
|
|
1047
|
+
new RspackManifestPlugin({
|
|
998
1048
|
fileName: isEnvProduction
|
|
999
|
-
?
|
|
1000
|
-
: path.resolve(options.buildDirectory,
|
|
1049
|
+
? config.assetsManifestFile
|
|
1050
|
+
: path.resolve(options.buildDirectory, config.assetsManifestFile),
|
|
1001
1051
|
writeToFileEmit: true,
|
|
1002
1052
|
useLegacyEmit: true,
|
|
1003
1053
|
publicPath: '',
|
|
1004
|
-
generate:
|
|
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
|
|
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
|
|
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
|
|
1236
|
+
runtimeChunk: helperOptions.config.moduleFederation ? false : 'single',
|
|
1237
|
+
minimizer: [new rspack.SwcJsMinimizerRspackPlugin(swcMinifyOptions), cssMinimizer],
|
|
1188
1238
|
};
|
|
1189
1239
|
return optimization;
|
|
1190
1240
|
}
|