@gravity-ui/app-builder 0.14.2-beta.0 → 0.15.1-beta.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.
- package/dist/commands/build/build-service/client.js +1 -4
- package/dist/commands/dev/client.js +24 -8
- package/dist/common/config.js +8 -7
- package/dist/common/logger/colors.d.ts +1 -1
- package/dist/common/logger/index.d.ts +1 -1
- package/dist/common/models/index.d.ts +1 -0
- package/dist/common/s3-upload/webpack-plugin.d.ts +2 -2
- package/dist/common/s3-upload/webpack-plugin.js +2 -3
- package/dist/common/typescript/compile.js +7 -7
- package/dist/common/typescript/watch.js +6 -6
- package/dist/common/webpack/compile.d.ts +1 -1
- package/dist/common/webpack/compile.js +34 -10
- package/dist/common/webpack/config.d.ts +8 -3
- package/dist/common/webpack/config.js +373 -117
- package/dist/common/webpack/node-externals.d.ts +4 -2
- package/dist/common/webpack/node-externals.js +5 -5
- package/dist/common/webpack/progress-plugin.d.ts +4 -5
- package/dist/common/webpack/progress-plugin.js +11 -33
- package/dist/common/webpack/rspack.d.ts +7 -0
- package/dist/common/{rspack/utils.js → webpack/rspack.js} +57 -27
- package/dist/common/webpack/storybook.d.ts +1 -1
- package/dist/common/webpack/utils.d.ts +2 -2
- package/dist/common/webpack/utils.js +4 -2
- package/dist/common/webpack/worker/worker-loader.d.ts +2 -2
- package/dist/common/webpack/worker/worker-loader.js +17 -17
- package/dist/create-cli.d.ts +2 -2
- package/package.json +1 -3
- package/dist/common/rspack/compile.d.ts +0 -2
- package/dist/common/rspack/compile.js +0 -27
- package/dist/common/rspack/config.d.ts +0 -24
- package/dist/common/rspack/config.js +0 -772
- package/dist/common/rspack/lazy-client.d.ts +0 -1
- package/dist/common/rspack/lazy-client.js +0 -63
- package/dist/common/rspack/progress-plugin.d.ts +0 -11
- package/dist/common/rspack/progress-plugin.js +0 -43
- package/dist/common/rspack/public-path.d.ts +0 -1
- package/dist/common/rspack/public-path.js +0 -4
- package/dist/common/rspack/utils.d.ts +0 -4
- package/dist/common/rspack/worker/public-path.worker.d.ts +0 -1
- package/dist/common/rspack/worker/public-path.worker.js +0 -3
- package/dist/common/rspack/worker/web-worker.d.mts +0 -8
- package/dist/common/rspack/worker/web-worker.mjs +0 -32
- package/dist/common/rspack/worker/worker-loader.d.ts +0 -4
- package/dist/common/rspack/worker/worker-loader.js +0 -177
|
@@ -27,10 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.webpackConfigFactory = webpackConfigFactory;
|
|
30
|
+
exports.rspackConfigFactory = rspackConfigFactory;
|
|
30
31
|
exports.configureModuleRules = configureModuleRules;
|
|
31
32
|
exports.configureResolve = configureResolve;
|
|
32
33
|
exports.configureOptimization = configureOptimization;
|
|
33
|
-
/* eslint-disable complexity */
|
|
34
34
|
const path = __importStar(require("node:path"));
|
|
35
35
|
const fs = __importStar(require("node:fs"));
|
|
36
36
|
const webpack = __importStar(require("webpack"));
|
|
@@ -44,6 +44,11 @@ const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-re
|
|
|
44
44
|
const moment_timezone_data_webpack_plugin_1 = __importDefault(require("moment-timezone-data-webpack-plugin"));
|
|
45
45
|
const webpack_plugin_1 = __importDefault(require("@statoscope/webpack-plugin"));
|
|
46
46
|
const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
|
|
47
|
+
const core_1 = require("@rspack/core");
|
|
48
|
+
const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
|
|
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"));
|
|
47
52
|
const paths_1 = __importDefault(require("../paths"));
|
|
48
53
|
const babel_1 = require("../babel");
|
|
49
54
|
const progress_plugin_1 = require("./progress-plugin");
|
|
@@ -54,10 +59,11 @@ const utils_2 = require("../typescript/utils");
|
|
|
54
59
|
const node_externals_1 = require("./node-externals");
|
|
55
60
|
const imagesSizeLimit = 2048;
|
|
56
61
|
const fontSizeLimit = 8192;
|
|
57
|
-
|
|
62
|
+
const assetsManifestFile = 'assets-manifest.json';
|
|
63
|
+
function getHelperOptions({ webpackMode, config, logger, isSsr = false, }) {
|
|
58
64
|
const isEnvDevelopment = webpackMode === "development" /* WebpackMode.Dev */;
|
|
59
65
|
const isEnvProduction = webpackMode === "production" /* WebpackMode.Prod */;
|
|
60
|
-
|
|
66
|
+
return {
|
|
61
67
|
config,
|
|
62
68
|
logger,
|
|
63
69
|
isEnvDevelopment,
|
|
@@ -67,6 +73,11 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
67
73
|
entriesDirectory: isSsr ? paths_1.default.appSsrEntry : paths_1.default.appEntry,
|
|
68
74
|
isSsr,
|
|
69
75
|
};
|
|
76
|
+
}
|
|
77
|
+
async function webpackConfigFactory(options) {
|
|
78
|
+
const { config } = options;
|
|
79
|
+
const helperOptions = getHelperOptions(options);
|
|
80
|
+
const { isSsr, isEnvProduction } = helperOptions;
|
|
70
81
|
let externals = config.externals;
|
|
71
82
|
if (isSsr) {
|
|
72
83
|
externals =
|
|
@@ -78,7 +89,7 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
78
89
|
});
|
|
79
90
|
}
|
|
80
91
|
let webpackConfig = {
|
|
81
|
-
mode:
|
|
92
|
+
mode: isEnvProduction ? 'production' : 'development',
|
|
82
93
|
context: paths_1.default.app,
|
|
83
94
|
bail: isEnvProduction,
|
|
84
95
|
target: isSsr ? 'node' : undefined,
|
|
@@ -89,7 +100,7 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
89
100
|
module: {
|
|
90
101
|
rules: configureModuleRules(helperOptions),
|
|
91
102
|
},
|
|
92
|
-
plugins:
|
|
103
|
+
plugins: configureWebpackPlugins(helperOptions),
|
|
93
104
|
optimization: configureOptimization(helperOptions),
|
|
94
105
|
externals,
|
|
95
106
|
node: config.node,
|
|
@@ -107,12 +118,57 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
107
118
|
},
|
|
108
119
|
cache: config.cache,
|
|
109
120
|
};
|
|
110
|
-
webpackConfig = await config.webpack(webpackConfig, {
|
|
121
|
+
webpackConfig = await config.webpack(webpackConfig, {
|
|
122
|
+
configType: isEnvProduction ? 'production' : 'development',
|
|
123
|
+
isSsr,
|
|
124
|
+
});
|
|
111
125
|
if (config.debugWebpack) {
|
|
112
126
|
(0, log_config_1.logConfig)('Preview webpack config', webpackConfig);
|
|
113
127
|
}
|
|
114
128
|
return webpackConfig;
|
|
115
129
|
}
|
|
130
|
+
async function rspackConfigFactory(options) {
|
|
131
|
+
const { config } = options;
|
|
132
|
+
const helperOptions = getHelperOptions(options);
|
|
133
|
+
const { isSsr, isEnvProduction, isEnvDevelopment } = helperOptions;
|
|
134
|
+
// Cache is required for lazy compilation
|
|
135
|
+
const cache = Boolean(config.cache) || (isEnvDevelopment && Boolean(config.lazyCompilation));
|
|
136
|
+
let rspackConfig = {
|
|
137
|
+
mode: isEnvProduction ? 'production' : 'development',
|
|
138
|
+
context: paths_1.default.app,
|
|
139
|
+
bail: isEnvProduction,
|
|
140
|
+
target: isSsr ? 'node' : undefined,
|
|
141
|
+
devtool: configureDevTool(helperOptions),
|
|
142
|
+
entry: configureEntry(helperOptions),
|
|
143
|
+
output: configureRspackOutput(helperOptions),
|
|
144
|
+
resolve: configureRspackResolve(helperOptions),
|
|
145
|
+
module: {
|
|
146
|
+
rules: (0, rspack_1.prepareRspackRules)(configureModuleRules(helperOptions)),
|
|
147
|
+
},
|
|
148
|
+
plugins: configureRspackPlugins(helperOptions),
|
|
149
|
+
optimization: configureRspackOptimization(helperOptions),
|
|
150
|
+
// TODO externals,
|
|
151
|
+
node: config.node,
|
|
152
|
+
watchOptions: configureWatchOptions(helperOptions),
|
|
153
|
+
ignoreWarnings: [/Failed to parse source map/],
|
|
154
|
+
infrastructureLogging: config.verbose
|
|
155
|
+
? {
|
|
156
|
+
colors: true,
|
|
157
|
+
level: 'verbose',
|
|
158
|
+
}
|
|
159
|
+
: undefined,
|
|
160
|
+
experiments: configureRspackExperiments(helperOptions),
|
|
161
|
+
cache,
|
|
162
|
+
};
|
|
163
|
+
rspackConfig = await config.rspack(rspackConfig, {
|
|
164
|
+
configType: isEnvProduction ? 'production' : 'development',
|
|
165
|
+
isSsr,
|
|
166
|
+
});
|
|
167
|
+
if (config.debugWebpack) {
|
|
168
|
+
(0, log_config_1.logConfig)('Preview rspack config', rspackConfig);
|
|
169
|
+
}
|
|
170
|
+
return rspackConfig;
|
|
171
|
+
}
|
|
116
172
|
function configureModuleRules(helperOptions, additionalRules = []) {
|
|
117
173
|
const jsLoader = createJavaScriptLoader(helperOptions);
|
|
118
174
|
return [
|
|
@@ -183,6 +239,56 @@ function configureExperiments({ config, isEnvProduction, isSsr, }) {
|
|
|
183
239
|
lazyCompilation,
|
|
184
240
|
};
|
|
185
241
|
}
|
|
242
|
+
function configureRspackExperiments({ config, isEnvProduction, isSsr, }) {
|
|
243
|
+
if (isSsr) {
|
|
244
|
+
return config.ssr?.moduleType === 'esm' ? { outputModule: true } : undefined;
|
|
245
|
+
}
|
|
246
|
+
if (isEnvProduction) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
let lazyCompilation;
|
|
250
|
+
let port;
|
|
251
|
+
if (config.lazyCompilation) {
|
|
252
|
+
if (typeof config.lazyCompilation === 'object') {
|
|
253
|
+
port = config.lazyCompilation.port;
|
|
254
|
+
}
|
|
255
|
+
lazyCompilation = {
|
|
256
|
+
// Lazy compilation works without problems only with lazy imports
|
|
257
|
+
// See https://github.com/web-infra-dev/rspack/issues/8503
|
|
258
|
+
entries: false,
|
|
259
|
+
imports: true,
|
|
260
|
+
backend: {
|
|
261
|
+
client: require.resolve('./lazy-client.js'),
|
|
262
|
+
...(port
|
|
263
|
+
? {
|
|
264
|
+
listen: {
|
|
265
|
+
port,
|
|
266
|
+
},
|
|
267
|
+
}
|
|
268
|
+
: {}),
|
|
269
|
+
},
|
|
270
|
+
test(module) {
|
|
271
|
+
// make sure that lazy-client.js won't be lazy compiled)
|
|
272
|
+
return !module.nameForCondition().endsWith('lazy-client.js');
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
cache: {
|
|
278
|
+
type: 'persistent',
|
|
279
|
+
snapshot: {
|
|
280
|
+
managedPaths: config.watchOptions?.watchPackages ? [] : undefined,
|
|
281
|
+
},
|
|
282
|
+
storage: {
|
|
283
|
+
type: 'filesystem',
|
|
284
|
+
directory: typeof config.cache === 'object' && 'cacheDirectory' in config.cache
|
|
285
|
+
? config.cache.cacheDirectory
|
|
286
|
+
: undefined,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
lazyCompilation,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
186
292
|
function configureResolve({ isEnvProduction, config }) {
|
|
187
293
|
const alias = { ...config.alias };
|
|
188
294
|
for (const [key, value] of Object.entries(alias)) {
|
|
@@ -204,6 +310,16 @@ function configureResolve({ isEnvProduction, config }) {
|
|
|
204
310
|
fallback: config.fallback,
|
|
205
311
|
};
|
|
206
312
|
}
|
|
313
|
+
function configureRspackResolve(helperOptions) {
|
|
314
|
+
const { alias, modules, extensions, symlinks, fallback } = configureResolve(helperOptions);
|
|
315
|
+
return {
|
|
316
|
+
alias: Array.isArray(alias) ? undefined : alias,
|
|
317
|
+
modules,
|
|
318
|
+
extensions,
|
|
319
|
+
symlinks,
|
|
320
|
+
fallback: Array.isArray(fallback) ? undefined : fallback,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
207
323
|
function createEntryArray(entry) {
|
|
208
324
|
return [require.resolve('./public-path'), entry];
|
|
209
325
|
}
|
|
@@ -250,6 +366,18 @@ function configureOutput(options) {
|
|
|
250
366
|
...ssrOptions,
|
|
251
367
|
};
|
|
252
368
|
}
|
|
369
|
+
function configureRspackOutput(options) {
|
|
370
|
+
const { filename, chunkFilename, library, chunkFormat, path, pathinfo } = configureOutput(options);
|
|
371
|
+
return {
|
|
372
|
+
filename: typeof filename === 'string' ? filename : undefined,
|
|
373
|
+
chunkFilename: typeof chunkFilename === 'string' ? chunkFilename : undefined,
|
|
374
|
+
library,
|
|
375
|
+
chunkFormat,
|
|
376
|
+
path,
|
|
377
|
+
pathinfo,
|
|
378
|
+
clean: false,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
253
381
|
function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, isSsr, }) {
|
|
254
382
|
const plugins = [];
|
|
255
383
|
if (!isSsr) {
|
|
@@ -327,7 +455,9 @@ function createWorkerRule(options) {
|
|
|
327
455
|
loader: require.resolve('./worker/worker-loader'),
|
|
328
456
|
}
|
|
329
457
|
: {
|
|
330
|
-
loader: require.resolve('
|
|
458
|
+
loader: require.resolve(options.config.bundler === 'rspack'
|
|
459
|
+
? 'worker-rspack-loader'
|
|
460
|
+
: 'worker-loader'),
|
|
331
461
|
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
332
462
|
// service instead
|
|
333
463
|
options: {
|
|
@@ -371,6 +501,7 @@ function createStylesRule(options) {
|
|
|
371
501
|
};
|
|
372
502
|
}
|
|
373
503
|
function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, additionalRules) {
|
|
504
|
+
const isRspack = config.bundler === 'rspack';
|
|
374
505
|
const loaders = [];
|
|
375
506
|
if (!config.transformCssWithLightningCss) {
|
|
376
507
|
loaders.push({
|
|
@@ -410,11 +541,17 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
|
|
|
410
541
|
},
|
|
411
542
|
});
|
|
412
543
|
if (isEnvProduction) {
|
|
413
|
-
loaders.unshift({
|
|
544
|
+
loaders.unshift({
|
|
545
|
+
loader: isRspack ? core_1.CssExtractRspackPlugin.loader : mini_css_extract_plugin_1.default.loader,
|
|
546
|
+
options: { emit: !isSsr },
|
|
547
|
+
});
|
|
414
548
|
}
|
|
415
549
|
if (isEnvDevelopment) {
|
|
416
550
|
if (isSsr || config.ssr) {
|
|
417
|
-
loaders.unshift({
|
|
551
|
+
loaders.unshift({
|
|
552
|
+
loader: isRspack ? core_1.CssExtractRspackPlugin.loader : mini_css_extract_plugin_1.default.loader,
|
|
553
|
+
options: { emit: !isSsr },
|
|
554
|
+
});
|
|
418
555
|
}
|
|
419
556
|
else {
|
|
420
557
|
loaders.unshift({
|
|
@@ -568,47 +705,42 @@ function createMomentTimezoneDataPlugin(options = {}) {
|
|
|
568
705
|
const endYear = options.endYear ?? currentYear;
|
|
569
706
|
return new moment_timezone_data_webpack_plugin_1.default({ ...options, startYear, endYear });
|
|
570
707
|
}
|
|
571
|
-
function
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
],
|
|
583
|
-
}),
|
|
584
|
-
new webpack_manifest_plugin_1.WebpackManifestPlugin({
|
|
585
|
-
writeToFileEmit: true,
|
|
586
|
-
publicPath: '',
|
|
587
|
-
}),
|
|
588
|
-
new webpack_assets_manifest_1.default(isEnvProduction
|
|
589
|
-
? {
|
|
590
|
-
entrypoints: true,
|
|
591
|
-
output: manifestFile,
|
|
592
|
-
}
|
|
593
|
-
: {
|
|
594
|
-
entrypoints: true,
|
|
595
|
-
writeToDisk: true,
|
|
596
|
-
output: path.resolve(options.buildDirectory, manifestFile),
|
|
597
|
-
}),
|
|
598
|
-
new webpack.DefinePlugin({
|
|
599
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
600
|
-
'process.env.IS_SSR': JSON.stringify(isSsr),
|
|
601
|
-
...config.definitions,
|
|
602
|
-
}),
|
|
603
|
-
];
|
|
604
|
-
if (options.logger) {
|
|
605
|
-
plugins.push(new progress_plugin_1.ProgressPlugin({ logger: options.logger }));
|
|
708
|
+
function getDefinitions({ config, isSsr }) {
|
|
709
|
+
return {
|
|
710
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
711
|
+
'process.env.IS_SSR': JSON.stringify(isSsr),
|
|
712
|
+
...config.definitions,
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function getContextReplacements({ config, isSsr }) {
|
|
716
|
+
const contextReplacement = config.contextReplacement || {};
|
|
717
|
+
if (isSsr) {
|
|
718
|
+
return [];
|
|
606
719
|
}
|
|
607
|
-
|
|
608
|
-
|
|
720
|
+
const replacements = [
|
|
721
|
+
{
|
|
722
|
+
resourceRegExp: /moment[\\/]locale$/, // eslint-disable-next-line security/detect-non-literal-regexp
|
|
723
|
+
newResource: new RegExp(`^\\./(${(contextReplacement.locale || ['ru']).join('|')})$`),
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
resourceRegExp: /dayjs[\\/]locale$/,
|
|
727
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
728
|
+
newResource: new RegExp(`^\\./(${(contextReplacement.locale || ['ru']).join('|')})\\.js$`),
|
|
729
|
+
},
|
|
730
|
+
];
|
|
731
|
+
if (contextReplacement['highlight.js']) {
|
|
732
|
+
replacements.push({
|
|
733
|
+
resourceRegExp: /highlight\.js[\\/]lib[\\/]languages$/,
|
|
734
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
735
|
+
newResource: new RegExp(`^\\./(${contextReplacement['highlight.js'].join('|')})$`),
|
|
736
|
+
});
|
|
609
737
|
}
|
|
610
|
-
|
|
611
|
-
|
|
738
|
+
return replacements;
|
|
739
|
+
}
|
|
740
|
+
function getForkTsCheckerOptions({ config, }) {
|
|
741
|
+
return config.forkTsChecker === false
|
|
742
|
+
? undefined
|
|
743
|
+
: {
|
|
612
744
|
...config.forkTsChecker,
|
|
613
745
|
typescript: {
|
|
614
746
|
typescriptPath: (0, utils_2.resolveTypescript)(),
|
|
@@ -619,8 +751,31 @@ function configurePlugins(options) {
|
|
|
619
751
|
mode: 'write-references',
|
|
620
752
|
...config.forkTsChecker?.typescript,
|
|
621
753
|
},
|
|
622
|
-
}
|
|
623
|
-
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function getCssExtractPluginOptions({ isEnvProduction }) {
|
|
757
|
+
return {
|
|
758
|
+
filename: isEnvProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css',
|
|
759
|
+
chunkFilename: isEnvProduction
|
|
760
|
+
? 'css/[name].[contenthash:8].chunk.css'
|
|
761
|
+
: 'css/[name].chunk.css',
|
|
762
|
+
ignoreOrder: true,
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
function configureCommonPlugins(options) {
|
|
766
|
+
const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
|
|
767
|
+
const excludeFromClean = config.excludeFromClean || [];
|
|
768
|
+
const plugins = [
|
|
769
|
+
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
770
|
+
verbose: config.verbose,
|
|
771
|
+
cleanOnceBeforeBuildPatterns: [
|
|
772
|
+
'**/*',
|
|
773
|
+
...(isEnvDevelopment ? ['!manifest.json'] : []),
|
|
774
|
+
...excludeFromClean,
|
|
775
|
+
],
|
|
776
|
+
}),
|
|
777
|
+
...(options.logger ? [new progress_plugin_1.ProgressPlugin({ logger: options.logger })] : []),
|
|
778
|
+
];
|
|
624
779
|
if (config.detectCircularDependencies) {
|
|
625
780
|
let circularPluginOptions = {
|
|
626
781
|
exclude: /node_modules/,
|
|
@@ -639,27 +794,6 @@ function configurePlugins(options) {
|
|
|
639
794
|
reportFilename: 'stats.html',
|
|
640
795
|
}));
|
|
641
796
|
}
|
|
642
|
-
if (config.analyzeBundle === 'statoscope') {
|
|
643
|
-
const customStatoscopeConfig = config.statoscopeConfig || {};
|
|
644
|
-
plugins.push(new webpack_plugin_1.default({
|
|
645
|
-
saveReportTo: path.resolve(options.buildDirectory, 'report.html'),
|
|
646
|
-
saveStatsTo: path.resolve(options.buildDirectory, 'stats.json'),
|
|
647
|
-
open: false,
|
|
648
|
-
statsOptions: {
|
|
649
|
-
all: true,
|
|
650
|
-
},
|
|
651
|
-
...customStatoscopeConfig,
|
|
652
|
-
}));
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
if (isEnvProduction || isSsr || config.ssr) {
|
|
656
|
-
plugins.push(new mini_css_extract_plugin_1.default({
|
|
657
|
-
filename: isEnvProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css',
|
|
658
|
-
chunkFilename: isEnvProduction
|
|
659
|
-
? 'css/[name].[contenthash:8].chunk.css'
|
|
660
|
-
: 'css/[name].chunk.css',
|
|
661
|
-
ignoreOrder: true,
|
|
662
|
-
}));
|
|
663
797
|
}
|
|
664
798
|
if (!isSsr) {
|
|
665
799
|
if (config.monaco) {
|
|
@@ -672,45 +806,130 @@ function configurePlugins(options) {
|
|
|
672
806
|
publicPath: path.normalize(config.publicPathPrefix + '/build/'),
|
|
673
807
|
}));
|
|
674
808
|
}
|
|
675
|
-
const contextReplacement = config.contextReplacement || {};
|
|
676
809
|
plugins.push(createMomentTimezoneDataPlugin(config.momentTz));
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
new RegExp(`^\\./(${(contextReplacement.locale || ['ru']).join('|')})\\.js$`)));
|
|
683
|
-
if (contextReplacement['highlight.js']) {
|
|
684
|
-
plugins.push(new webpack.ContextReplacementPlugin(/highlight\.js[\\/]lib[\\/]languages$/,
|
|
685
|
-
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
686
|
-
new RegExp(`^\\./(${contextReplacement['highlight.js'].join('|')})$`)));
|
|
810
|
+
}
|
|
811
|
+
if (isEnvProduction) {
|
|
812
|
+
if (config.sentryConfig) {
|
|
813
|
+
const sentryPlugin = require('@sentry/webpack-plugin').sentryWebpackPlugin;
|
|
814
|
+
plugins.push(sentryPlugin({ ...config.sentryConfig }));
|
|
687
815
|
}
|
|
816
|
+
}
|
|
817
|
+
if (config.cdn) {
|
|
818
|
+
plugins.push(...(0, s3_upload_1.createS3UploadPlugins)(config, options.logger));
|
|
819
|
+
}
|
|
820
|
+
return plugins;
|
|
821
|
+
}
|
|
822
|
+
function configureWebpackPlugins(options) {
|
|
823
|
+
const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
|
|
824
|
+
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
825
|
+
const webpackPlugins = [
|
|
826
|
+
...configureCommonPlugins(options),
|
|
827
|
+
new webpack.DefinePlugin(getDefinitions(options)),
|
|
828
|
+
new webpack_manifest_plugin_1.WebpackManifestPlugin({
|
|
829
|
+
writeToFileEmit: true,
|
|
830
|
+
publicPath: '',
|
|
831
|
+
}),
|
|
832
|
+
new webpack_assets_manifest_1.default(isEnvProduction
|
|
833
|
+
? {
|
|
834
|
+
entrypoints: true,
|
|
835
|
+
output: assetsManifestFile,
|
|
836
|
+
}
|
|
837
|
+
: {
|
|
838
|
+
entrypoints: true,
|
|
839
|
+
writeToDisk: true,
|
|
840
|
+
output: path.resolve(options.buildDirectory, assetsManifestFile),
|
|
841
|
+
}),
|
|
842
|
+
...(process.env.WEBPACK_PROFILE === 'true' ? [new webpack.debug.ProfilingPlugin()] : []),
|
|
843
|
+
...(forkTsCheckerOptions ? [new fork_ts_checker_webpack_plugin_1.default(forkTsCheckerOptions)] : []),
|
|
844
|
+
];
|
|
845
|
+
if (isEnvProduction || isSsr || config.ssr) {
|
|
846
|
+
webpackPlugins.push(new mini_css_extract_plugin_1.default(getCssExtractPluginOptions(options)));
|
|
847
|
+
}
|
|
848
|
+
if (isEnvProduction) {
|
|
849
|
+
if (config.analyzeBundle === 'statoscope') {
|
|
850
|
+
const customStatoscopeConfig = config.statoscopeConfig || {};
|
|
851
|
+
webpackPlugins.push(new webpack_plugin_1.default({
|
|
852
|
+
saveReportTo: path.resolve(options.buildDirectory, 'report.html'),
|
|
853
|
+
saveStatsTo: path.resolve(options.buildDirectory, 'stats.json'),
|
|
854
|
+
open: false,
|
|
855
|
+
statsOptions: {
|
|
856
|
+
all: true,
|
|
857
|
+
},
|
|
858
|
+
...customStatoscopeConfig,
|
|
859
|
+
}));
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
if (!isSsr) {
|
|
863
|
+
const contextReplacements = getContextReplacements(options);
|
|
864
|
+
contextReplacements.forEach(({ resourceRegExp, newResource }) => webpackPlugins.push(new webpack.ContextReplacementPlugin(resourceRegExp, newResource)));
|
|
688
865
|
if (isEnvDevelopment && config.reactRefresh !== false) {
|
|
689
866
|
const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`), } = config.devServer || {};
|
|
690
|
-
|
|
867
|
+
const reactRefreshConfig = config.reactRefresh({
|
|
691
868
|
overlay: { sockPath: webSocketPath },
|
|
692
869
|
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
693
|
-
})
|
|
870
|
+
});
|
|
871
|
+
webpackPlugins.push(new react_refresh_webpack_plugin_1.default(reactRefreshConfig));
|
|
694
872
|
}
|
|
695
873
|
if (config.polyfill?.process) {
|
|
696
|
-
|
|
874
|
+
webpackPlugins.push(new webpack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
697
875
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
876
|
+
}
|
|
877
|
+
return webpackPlugins;
|
|
878
|
+
}
|
|
879
|
+
function configureRspackPlugins(options) {
|
|
880
|
+
const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
|
|
881
|
+
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
882
|
+
const rspackPlugins = [
|
|
883
|
+
...configureCommonPlugins(options),
|
|
884
|
+
new core_1.rspack.DefinePlugin(getDefinitions(options)),
|
|
885
|
+
new rspack_manifest_plugin_1.RspackManifestPlugin({
|
|
886
|
+
fileName: isEnvProduction
|
|
887
|
+
? assetsManifestFile
|
|
888
|
+
: path.resolve(paths_1.default.appBuild, assetsManifestFile),
|
|
889
|
+
writeToFileEmit: true,
|
|
890
|
+
useLegacyEmit: true,
|
|
891
|
+
publicPath: '',
|
|
892
|
+
generate: rspack_1.generateAssetsManifest,
|
|
893
|
+
}),
|
|
894
|
+
...(forkTsCheckerOptions ? [new ts_checker_rspack_plugin_1.TsCheckerRspackPlugin(forkTsCheckerOptions)] : []),
|
|
895
|
+
];
|
|
896
|
+
if (isEnvProduction || isSsr || config.ssr) {
|
|
897
|
+
rspackPlugins.push(new core_1.CssExtractRspackPlugin(getCssExtractPluginOptions(options)));
|
|
898
|
+
}
|
|
899
|
+
// TODO add rsdoctor plugin
|
|
900
|
+
if (!isSsr) {
|
|
901
|
+
const contextReplacements = getContextReplacements(options);
|
|
902
|
+
contextReplacements.forEach(({ resourceRegExp, newResource }) => rspackPlugins.push(new core_1.rspack.ContextReplacementPlugin(resourceRegExp, newResource)));
|
|
903
|
+
if (isEnvDevelopment && config.reactRefresh !== false) {
|
|
904
|
+
const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`), } = config.devServer || {};
|
|
905
|
+
const { overlay, ...reactRefreshConfig } = config.reactRefresh({
|
|
906
|
+
overlay: { sockPath: webSocketPath },
|
|
907
|
+
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
908
|
+
});
|
|
909
|
+
rspackPlugins.push(new plugin_react_refresh_1.default({
|
|
910
|
+
...reactRefreshConfig,
|
|
911
|
+
overlay: typeof overlay === 'object'
|
|
912
|
+
? {
|
|
913
|
+
entry: typeof overlay.entry === 'string' ? overlay.entry : undefined,
|
|
914
|
+
module: typeof overlay.module === 'string'
|
|
915
|
+
? overlay.module
|
|
916
|
+
: undefined,
|
|
917
|
+
sockPath: overlay.sockPath,
|
|
918
|
+
sockHost: overlay.sockHost,
|
|
919
|
+
sockPort: overlay.sockPort?.toString(),
|
|
920
|
+
sockProtocol: overlay.sockProtocol,
|
|
921
|
+
sockIntegration: overlay.sockIntegration === 'wds' ? 'wds' : undefined,
|
|
922
|
+
}
|
|
923
|
+
: undefined,
|
|
924
|
+
}));
|
|
703
925
|
}
|
|
704
|
-
if (config.
|
|
705
|
-
|
|
926
|
+
if (config.polyfill?.process) {
|
|
927
|
+
rspackPlugins.push(new core_1.rspack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
706
928
|
}
|
|
707
929
|
}
|
|
708
|
-
return
|
|
930
|
+
return rspackPlugins;
|
|
709
931
|
}
|
|
710
|
-
function
|
|
711
|
-
if (isSsr) {
|
|
712
|
-
return {};
|
|
713
|
-
}
|
|
932
|
+
function getOptimizationSplitChunks({ config }) {
|
|
714
933
|
const configVendors = config.vendors ?? [];
|
|
715
934
|
let vendorsList = [
|
|
716
935
|
'react',
|
|
@@ -732,28 +951,35 @@ function configureOptimization({ config, isSsr }) {
|
|
|
732
951
|
vendorsList = vendorsList.concat(configVendors);
|
|
733
952
|
}
|
|
734
953
|
const useVendorsList = vendorsList.length > 0;
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
reuseExistingChunk: true,
|
|
754
|
-
},
|
|
954
|
+
return {
|
|
955
|
+
chunks: 'all',
|
|
956
|
+
cacheGroups: {
|
|
957
|
+
...(useVendorsList
|
|
958
|
+
? {
|
|
959
|
+
defaultVendors: {
|
|
960
|
+
name: 'vendors',
|
|
961
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
962
|
+
test: new RegExp(`([\\\\/])node_modules\\1(${vendorsList.join('|')})\\1`),
|
|
963
|
+
priority: Infinity,
|
|
964
|
+
},
|
|
965
|
+
}
|
|
966
|
+
: undefined),
|
|
967
|
+
css: {
|
|
968
|
+
type: 'css/mini-extract',
|
|
969
|
+
enforce: true,
|
|
970
|
+
minChunks: 2,
|
|
971
|
+
reuseExistingChunk: true,
|
|
755
972
|
},
|
|
756
973
|
},
|
|
974
|
+
};
|
|
975
|
+
}
|
|
976
|
+
function configureOptimization(helperOptions) {
|
|
977
|
+
const { config, isSsr } = helperOptions;
|
|
978
|
+
if (isSsr) {
|
|
979
|
+
return {};
|
|
980
|
+
}
|
|
981
|
+
const optimization = {
|
|
982
|
+
splitChunks: getOptimizationSplitChunks(helperOptions),
|
|
757
983
|
runtimeChunk: 'single',
|
|
758
984
|
minimizer: [
|
|
759
985
|
(compiler) => {
|
|
@@ -803,3 +1029,33 @@ function configureOptimization({ config, isSsr }) {
|
|
|
803
1029
|
};
|
|
804
1030
|
return optimization;
|
|
805
1031
|
}
|
|
1032
|
+
function configureRspackOptimization(helperOptions) {
|
|
1033
|
+
const { config, isSsr } = helperOptions;
|
|
1034
|
+
if (isSsr) {
|
|
1035
|
+
return {};
|
|
1036
|
+
}
|
|
1037
|
+
const optimization = {
|
|
1038
|
+
splitChunks: getOptimizationSplitChunks(helperOptions),
|
|
1039
|
+
runtimeChunk: 'single',
|
|
1040
|
+
minimizer: [
|
|
1041
|
+
new core_1.rspack.SwcJsMinimizerRspackPlugin({
|
|
1042
|
+
minimizerOptions: {
|
|
1043
|
+
mangle: !config.reactProfiling,
|
|
1044
|
+
compress: {
|
|
1045
|
+
passes: 2,
|
|
1046
|
+
},
|
|
1047
|
+
format: {
|
|
1048
|
+
safari10: config.safari10,
|
|
1049
|
+
},
|
|
1050
|
+
},
|
|
1051
|
+
}),
|
|
1052
|
+
new core_1.rspack.LightningCssMinimizerRspackPlugin({
|
|
1053
|
+
minimizerOptions: {
|
|
1054
|
+
// Plugin will read the browserslist itself and generate targets
|
|
1055
|
+
targets: [],
|
|
1056
|
+
},
|
|
1057
|
+
}),
|
|
1058
|
+
],
|
|
1059
|
+
};
|
|
1060
|
+
return optimization;
|
|
1061
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type * as webpack from 'webpack';
|
|
2
1
|
type Pattern = RegExp | ((v: string) => boolean) | string;
|
|
3
2
|
export interface NodeExternalsOptions {
|
|
4
3
|
noExternal?: Pattern | Pattern[];
|
|
5
4
|
module?: boolean;
|
|
6
5
|
}
|
|
7
|
-
export declare function nodeExternals({ noExternal, module }: NodeExternalsOptions): (data:
|
|
6
|
+
export declare function nodeExternals({ noExternal, module }: NodeExternalsOptions): (data: {
|
|
7
|
+
request?: string;
|
|
8
|
+
dependencyType?: string;
|
|
9
|
+
}) => Promise<string | undefined>;
|
|
8
10
|
export {};
|