@gravity-ui/app-builder 0.14.1 → 0.14.2-beta.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/dist/commands/build/build-service/client.js +4 -1
- package/dist/commands/dev/client.d.ts +2 -1
- package/dist/commands/dev/client.js +57 -24
- package/dist/common/config.js +2 -0
- package/dist/common/library/index.js +1 -0
- 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 +13 -0
- package/dist/common/rspack/compile.d.ts +2 -0
- package/dist/common/rspack/compile.js +27 -0
- package/dist/common/rspack/config.d.ts +24 -0
- package/dist/common/rspack/config.js +772 -0
- package/dist/common/rspack/lazy-client.d.ts +1 -0
- package/dist/common/rspack/lazy-client.js +63 -0
- package/dist/common/rspack/progress-plugin.d.ts +11 -0
- package/dist/common/rspack/progress-plugin.js +43 -0
- package/dist/common/rspack/public-path.d.ts +1 -0
- package/dist/common/rspack/public-path.js +4 -0
- package/dist/common/rspack/utils.d.ts +4 -0
- package/dist/common/rspack/utils.js +81 -0
- package/dist/common/rspack/worker/public-path.worker.d.ts +1 -0
- package/dist/common/rspack/worker/public-path.worker.js +3 -0
- package/dist/common/rspack/worker/web-worker.d.mts +8 -0
- package/dist/common/rspack/worker/web-worker.mjs +32 -0
- package/dist/common/rspack/worker/worker-loader.d.ts +4 -0
- package/dist/common/rspack/worker/worker-loader.js +177 -0
- package/dist/common/s3-upload/create-plugin.d.ts +3 -0
- package/dist/common/s3-upload/create-plugin.js +47 -0
- package/dist/common/s3-upload/index.d.ts +1 -0
- package/dist/common/s3-upload/index.js +3 -1
- package/dist/common/webpack/config.js +1 -40
- package/dist/common/webpack/progress-plugin.d.ts +3 -1
- package/dist/common/webpack/progress-plugin.js +9 -2
- package/dist/common/webpack/storybook.d.ts +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,772 @@
|
|
|
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.generateManifest = void 0;
|
|
30
|
+
exports.rspackConfigFactory = rspackConfigFactory;
|
|
31
|
+
exports.configureModuleRules = configureModuleRules;
|
|
32
|
+
exports.configureResolve = configureResolve;
|
|
33
|
+
exports.configureOptimization = configureOptimization;
|
|
34
|
+
/* eslint-disable complexity */
|
|
35
|
+
const path = __importStar(require("node:path"));
|
|
36
|
+
const fs = __importStar(require("node:fs"));
|
|
37
|
+
const core_1 = require("@rspack/core");
|
|
38
|
+
const utils_1 = require("../typescript/utils");
|
|
39
|
+
const ts_checker_rspack_plugin_1 = require("ts-checker-rspack-plugin");
|
|
40
|
+
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
41
|
+
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
42
|
+
const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
|
|
43
|
+
const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
|
|
44
|
+
const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
|
|
45
|
+
const paths_1 = __importDefault(require("../paths"));
|
|
46
|
+
const babel_1 = require("../babel");
|
|
47
|
+
const progress_plugin_1 = require("./progress-plugin");
|
|
48
|
+
const utils_2 = require("../webpack/utils");
|
|
49
|
+
const s3_upload_1 = require("../s3-upload");
|
|
50
|
+
const log_config_1 = require("../logger/log-config");
|
|
51
|
+
const imagesSizeLimit = 2048;
|
|
52
|
+
const fontSizeLimit = 8192;
|
|
53
|
+
const generateManifest = (seed, files, entries) => {
|
|
54
|
+
const manifestFiles = files.reduce((manifest, file) => {
|
|
55
|
+
manifest[file.name] = file.path;
|
|
56
|
+
return manifest;
|
|
57
|
+
}, seed);
|
|
58
|
+
const entrypoints = Object.keys(entries).reduce((previous, name) => {
|
|
59
|
+
return {
|
|
60
|
+
...previous,
|
|
61
|
+
[name]: {
|
|
62
|
+
assets: {
|
|
63
|
+
js: entries[name].filter((file) => file.endsWith('.js')),
|
|
64
|
+
css: entries[name].filter((file) => file.endsWith('.css')),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}, {});
|
|
69
|
+
return {
|
|
70
|
+
files: manifestFiles,
|
|
71
|
+
entrypoints,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
exports.generateManifest = generateManifest;
|
|
75
|
+
async function rspackConfigFactory(rspackMode, config, { logger } = {}) {
|
|
76
|
+
const isEnvDevelopment = rspackMode === "development" /* RspackMode.Dev */;
|
|
77
|
+
const isEnvProduction = rspackMode === "production" /* RspackMode.Prod */;
|
|
78
|
+
const helperOptions = {
|
|
79
|
+
config,
|
|
80
|
+
logger,
|
|
81
|
+
isEnvDevelopment,
|
|
82
|
+
isEnvProduction,
|
|
83
|
+
configType: rspackMode,
|
|
84
|
+
};
|
|
85
|
+
// Cache is required for lazy compilation
|
|
86
|
+
const cache = Boolean(config.cache) || (isEnvDevelopment && Boolean(config.lazyCompilation));
|
|
87
|
+
let rspackConfig = {
|
|
88
|
+
mode: rspackMode,
|
|
89
|
+
context: paths_1.default.app,
|
|
90
|
+
bail: isEnvProduction,
|
|
91
|
+
devtool: configureDevTool(helperOptions),
|
|
92
|
+
entry: configureEntry(helperOptions),
|
|
93
|
+
output: configureOutput(helperOptions),
|
|
94
|
+
resolve: configureResolve(helperOptions),
|
|
95
|
+
module: {
|
|
96
|
+
rules: configureModuleRules(helperOptions),
|
|
97
|
+
},
|
|
98
|
+
plugins: configurePlugins(helperOptions),
|
|
99
|
+
optimization: configureOptimization(helperOptions),
|
|
100
|
+
// TODO
|
|
101
|
+
// externals: config.externals,
|
|
102
|
+
node: config.node,
|
|
103
|
+
watchOptions: configureWatchOptions(helperOptions),
|
|
104
|
+
ignoreWarnings: [/Failed to parse source map/],
|
|
105
|
+
infrastructureLogging: config.verbose
|
|
106
|
+
? {
|
|
107
|
+
colors: true,
|
|
108
|
+
level: 'verbose',
|
|
109
|
+
}
|
|
110
|
+
: undefined,
|
|
111
|
+
experiments: configureExperiments(helperOptions),
|
|
112
|
+
cache,
|
|
113
|
+
};
|
|
114
|
+
rspackConfig = await config.rspack(rspackConfig, { configType: rspackMode });
|
|
115
|
+
if (config.debugWebpack) {
|
|
116
|
+
(0, log_config_1.logConfig)('Preview rspack config', rspackConfig);
|
|
117
|
+
}
|
|
118
|
+
return rspackConfig;
|
|
119
|
+
}
|
|
120
|
+
function configureModuleRules(helperOptions, additionalRules = []) {
|
|
121
|
+
const jsLoader = createJavaScriptLoader(helperOptions);
|
|
122
|
+
return [
|
|
123
|
+
...createSourceMapRules(!helperOptions.config.disableSourceMapGeneration),
|
|
124
|
+
{
|
|
125
|
+
oneOf: [
|
|
126
|
+
createWorkerRule(helperOptions),
|
|
127
|
+
createJavaScriptRule(helperOptions, jsLoader),
|
|
128
|
+
createStylesRule(helperOptions),
|
|
129
|
+
createSassStylesRule(helperOptions),
|
|
130
|
+
createIconsRule(helperOptions), // workaround for https://github.com/webpack/webpack/issues/9309
|
|
131
|
+
createIconsRule(helperOptions, jsLoader),
|
|
132
|
+
...createAssetsRules(helperOptions),
|
|
133
|
+
...additionalRules,
|
|
134
|
+
...createFallbackRules(helperOptions),
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
function configureDevTool({ isEnvProduction, config }) {
|
|
140
|
+
let format = 'cheap-module-source-map';
|
|
141
|
+
if (isEnvProduction) {
|
|
142
|
+
format = config.hiddenSourceMap ? 'hidden-source-map' : 'source-map';
|
|
143
|
+
}
|
|
144
|
+
return config.disableSourceMapGeneration ? false : format;
|
|
145
|
+
}
|
|
146
|
+
function configureWatchOptions({ config }) {
|
|
147
|
+
const watchOptions = {
|
|
148
|
+
...config.watchOptions,
|
|
149
|
+
followSymlinks: (config.watchOptions?.followSymlinks ??
|
|
150
|
+
(!config.symlinks && config.watchOptions?.watchPackages))
|
|
151
|
+
? true
|
|
152
|
+
: undefined,
|
|
153
|
+
};
|
|
154
|
+
delete watchOptions.watchPackages;
|
|
155
|
+
return watchOptions;
|
|
156
|
+
}
|
|
157
|
+
function configureExperiments({ config, isEnvProduction, }) {
|
|
158
|
+
let lazyCompilation;
|
|
159
|
+
let port;
|
|
160
|
+
if (!isEnvProduction && config.lazyCompilation) {
|
|
161
|
+
if (typeof config.lazyCompilation === 'object') {
|
|
162
|
+
port = config.lazyCompilation.port;
|
|
163
|
+
}
|
|
164
|
+
lazyCompilation = {
|
|
165
|
+
// Lazy compilation works without problems only with lazy imports
|
|
166
|
+
// See https://github.com/web-infra-dev/rspack/issues/8503
|
|
167
|
+
entries: false,
|
|
168
|
+
imports: true,
|
|
169
|
+
backend: {
|
|
170
|
+
client: require.resolve('./lazy-client.js'),
|
|
171
|
+
...(port
|
|
172
|
+
? {
|
|
173
|
+
listen: {
|
|
174
|
+
port,
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
: {}),
|
|
178
|
+
},
|
|
179
|
+
test(module) {
|
|
180
|
+
// make sure that lazy-client.js won't be lazy compiled)
|
|
181
|
+
return !module.nameForCondition().endsWith('lazy-client.js');
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
cache: {
|
|
187
|
+
type: 'persistent',
|
|
188
|
+
snapshot: {
|
|
189
|
+
managedPaths: config.watchOptions?.watchPackages ? [] : undefined,
|
|
190
|
+
},
|
|
191
|
+
storage: {
|
|
192
|
+
type: 'filesystem',
|
|
193
|
+
directory: typeof config.cache === 'object' && 'cacheDirectory' in config.cache
|
|
194
|
+
? config.cache.cacheDirectory
|
|
195
|
+
: undefined,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
lazyCompilation,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function configureResolve({ isEnvProduction, config }) {
|
|
202
|
+
const alias = { ...config.alias };
|
|
203
|
+
for (const [key, value] of Object.entries(alias)) {
|
|
204
|
+
alias[key] = path.resolve(paths_1.default.app, value);
|
|
205
|
+
}
|
|
206
|
+
if (isEnvProduction && config.reactProfiling) {
|
|
207
|
+
alias['react-dom$'] = 'react-dom/profiling';
|
|
208
|
+
alias['scheduler/tracing'] = 'scheduler/tracing-profiling';
|
|
209
|
+
}
|
|
210
|
+
const { aliases, modules = [] } = (0, utils_2.resolveTsConfigPathsToAlias)(paths_1.default.appClient);
|
|
211
|
+
return {
|
|
212
|
+
alias: {
|
|
213
|
+
...aliases,
|
|
214
|
+
...alias,
|
|
215
|
+
},
|
|
216
|
+
modules: ['node_modules', ...modules, ...(config.modules || [])],
|
|
217
|
+
extensions: ['.mjs', '.cjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
|
|
218
|
+
symlinks: config.symlinks,
|
|
219
|
+
fallback: Array.isArray(config.fallback) ? undefined : config.fallback,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function createEntryArray(entry) {
|
|
223
|
+
return [require.resolve('./public-path'), entry];
|
|
224
|
+
}
|
|
225
|
+
function addEntry(entry, file) {
|
|
226
|
+
const newEntry = path.resolve(paths_1.default.appEntry, file);
|
|
227
|
+
return {
|
|
228
|
+
...entry,
|
|
229
|
+
[path.parse(file).name]: createEntryArray(newEntry),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function configureEntry({ config }) {
|
|
233
|
+
let entries = fs.readdirSync(paths_1.default.appEntry).filter((file) => /\.[jt]sx?$/.test(file));
|
|
234
|
+
if (Array.isArray(config.entryFilter) && config.entryFilter.length) {
|
|
235
|
+
entries = entries.filter((entry) => config.entryFilter?.includes(entry.split('.')[0] ?? ''));
|
|
236
|
+
}
|
|
237
|
+
if (!entries.length) {
|
|
238
|
+
throw new Error('No entries were found after applying UI_CORE_ENTRY_FILTER');
|
|
239
|
+
}
|
|
240
|
+
return entries.reduce((entry, file) => addEntry(entry, file), {});
|
|
241
|
+
}
|
|
242
|
+
function getFileNames({ isEnvProduction }) {
|
|
243
|
+
return {
|
|
244
|
+
filename: isEnvProduction ? 'js/[name].[contenthash:8].js' : 'js/[name].js',
|
|
245
|
+
chunkFilename: isEnvProduction
|
|
246
|
+
? 'js/[name].[contenthash:8].chunk.js'
|
|
247
|
+
: 'js/[name].chunk.js',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function configureOutput({ isEnvDevelopment, ...rest }) {
|
|
251
|
+
return {
|
|
252
|
+
...getFileNames({ isEnvDevelopment, ...rest }),
|
|
253
|
+
path: paths_1.default.appBuild,
|
|
254
|
+
pathinfo: isEnvDevelopment,
|
|
255
|
+
clean: false,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, }) {
|
|
259
|
+
const plugins = [];
|
|
260
|
+
if (isEnvDevelopment && config.reactRefresh !== false) {
|
|
261
|
+
plugins.push([
|
|
262
|
+
require.resolve('react-refresh/babel'),
|
|
263
|
+
config.devServer?.webSocketPath
|
|
264
|
+
? {
|
|
265
|
+
overlay: {
|
|
266
|
+
sockPath: config.devServer.webSocketPath,
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
: undefined,
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
if (isEnvProduction) {
|
|
273
|
+
plugins.push([
|
|
274
|
+
require.resolve('babel-plugin-import'),
|
|
275
|
+
{ libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false },
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
const transformOptions = config.babel({
|
|
279
|
+
presets: [
|
|
280
|
+
(0, babel_1.babelPreset)({
|
|
281
|
+
newJsxTransform: config.newJsxTransform,
|
|
282
|
+
isSsr: false,
|
|
283
|
+
}),
|
|
284
|
+
],
|
|
285
|
+
plugins,
|
|
286
|
+
}, { configType, isSsr: false });
|
|
287
|
+
return {
|
|
288
|
+
loader: require.resolve('babel-loader'),
|
|
289
|
+
options: {
|
|
290
|
+
sourceType: 'unambiguous',
|
|
291
|
+
...transformOptions,
|
|
292
|
+
babelrc: false,
|
|
293
|
+
configFile: false,
|
|
294
|
+
compact: isEnvProduction,
|
|
295
|
+
sourceMaps: !config.disableSourceMapGeneration,
|
|
296
|
+
cacheCompression: isEnvProduction,
|
|
297
|
+
cacheDirectory: config.babelCacheDirectory ? config.babelCacheDirectory : true,
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
function createJavaScriptRule({ config, isEnvProduction }, jsLoader) {
|
|
302
|
+
const include = [
|
|
303
|
+
paths_1.default.appClient,
|
|
304
|
+
...(config.monaco && isEnvProduction
|
|
305
|
+
? [path.resolve(paths_1.default.appNodeModules, 'monaco-editor/esm/vs')]
|
|
306
|
+
: []),
|
|
307
|
+
...(config.includes || []),
|
|
308
|
+
];
|
|
309
|
+
return {
|
|
310
|
+
test: [/\.[jt]sx?$/, /\.[cm]js$/],
|
|
311
|
+
include,
|
|
312
|
+
use: jsLoader,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function createSourceMapRules(shouldUseSourceMap) {
|
|
316
|
+
if (shouldUseSourceMap) {
|
|
317
|
+
return [
|
|
318
|
+
{
|
|
319
|
+
test: [/\.jsx?$/, /\.[cm]js$/],
|
|
320
|
+
enforce: 'pre',
|
|
321
|
+
include: /node_modules/,
|
|
322
|
+
use: require.resolve('source-map-loader'),
|
|
323
|
+
},
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
return [];
|
|
327
|
+
}
|
|
328
|
+
function createWorkerRule(options) {
|
|
329
|
+
return {
|
|
330
|
+
test: /\.worker\.[jt]sx?$/,
|
|
331
|
+
exclude: /node_modules/,
|
|
332
|
+
use: [
|
|
333
|
+
options.config.newWebWorkerSyntax
|
|
334
|
+
? {
|
|
335
|
+
loader: require.resolve('./worker/worker-loader'),
|
|
336
|
+
}
|
|
337
|
+
: {
|
|
338
|
+
loader: require.resolve('worker-rspack-loader'),
|
|
339
|
+
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
340
|
+
// service instead
|
|
341
|
+
options: {
|
|
342
|
+
inline: 'no-fallback',
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
createJavaScriptLoader(options),
|
|
346
|
+
],
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function createSassStylesRule(options) {
|
|
350
|
+
const loaders = getCssLoaders(options, [
|
|
351
|
+
{
|
|
352
|
+
loader: require.resolve('resolve-url-loader'),
|
|
353
|
+
options: {
|
|
354
|
+
sourceMap: !options.config.disableSourceMapGeneration,
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
loader: require.resolve('sass-loader'),
|
|
359
|
+
options: {
|
|
360
|
+
sourceMap: true, // must be always true for work with resolve-url-loader
|
|
361
|
+
sassOptions: {
|
|
362
|
+
loadPaths: [paths_1.default.appClient],
|
|
363
|
+
silenceDeprecations: ['legacy-js-api', 'mixed-decls'],
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
]);
|
|
368
|
+
return {
|
|
369
|
+
test: /\.scss$/,
|
|
370
|
+
sideEffects: options.isEnvProduction ? true : undefined,
|
|
371
|
+
use: loaders,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function createStylesRule(options) {
|
|
375
|
+
const loaders = getCssLoaders(options);
|
|
376
|
+
return {
|
|
377
|
+
test: /\.css$/,
|
|
378
|
+
sideEffects: options.isEnvProduction ? true : undefined,
|
|
379
|
+
use: loaders,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }, additionalRules) {
|
|
383
|
+
const loaders = [];
|
|
384
|
+
if (!config.transformCssWithLightningCss) {
|
|
385
|
+
loaders.push({
|
|
386
|
+
loader: require.resolve('postcss-loader'),
|
|
387
|
+
options: {
|
|
388
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
389
|
+
postcssOptions: {
|
|
390
|
+
config: false,
|
|
391
|
+
plugins: [
|
|
392
|
+
[require.resolve('postcss-preset-env'), { enableClientSidePolyfills: false }],
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (Array.isArray(additionalRules) && additionalRules.length > 0) {
|
|
399
|
+
loaders.push(...additionalRules);
|
|
400
|
+
}
|
|
401
|
+
const importLoaders = loaders.length;
|
|
402
|
+
loaders.unshift({
|
|
403
|
+
loader: require.resolve('css-loader'),
|
|
404
|
+
options: {
|
|
405
|
+
url: {
|
|
406
|
+
filter: (url) => {
|
|
407
|
+
// ignore data uri
|
|
408
|
+
return !url.startsWith('data:');
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
sourceMap: !config.disableSourceMapGeneration,
|
|
412
|
+
importLoaders,
|
|
413
|
+
modules: {
|
|
414
|
+
auto: true,
|
|
415
|
+
localIdentName: '[name]__[local]--[hash:base64:5]',
|
|
416
|
+
exportLocalsConvention: 'camelCase',
|
|
417
|
+
exportOnlyLocals: false,
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
if (isEnvProduction) {
|
|
422
|
+
loaders.unshift({ loader: core_1.CssExtractRspackPlugin.loader });
|
|
423
|
+
}
|
|
424
|
+
if (isEnvDevelopment) {
|
|
425
|
+
loaders.unshift({
|
|
426
|
+
loader: require.resolve('style-loader'),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
return loaders;
|
|
430
|
+
}
|
|
431
|
+
function createIconsRule({ isEnvProduction, config }, jsLoader) {
|
|
432
|
+
const iconIncludes = config.icons || [];
|
|
433
|
+
return {
|
|
434
|
+
// eslint-disable-next-line security/detect-unsafe-regex
|
|
435
|
+
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
|
|
436
|
+
// we can't use one rule with issuer: /\.[jt]sx?$/ cause of https://github.com/webpack/webpack/issues/9309
|
|
437
|
+
issuer: jsLoader ? undefined : /\.s?css$/,
|
|
438
|
+
include: [
|
|
439
|
+
/icons\/.*\.svg$/,
|
|
440
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
441
|
+
...iconIncludes.map((dir) => new RegExp(dir)),
|
|
442
|
+
],
|
|
443
|
+
...(jsLoader
|
|
444
|
+
? {
|
|
445
|
+
use: [
|
|
446
|
+
jsLoader,
|
|
447
|
+
{
|
|
448
|
+
loader: require.resolve('@svgr/webpack'),
|
|
449
|
+
options: {
|
|
450
|
+
babel: false,
|
|
451
|
+
dimensions: false,
|
|
452
|
+
jsxRuntime: config.newJsxTransform ? 'automatic' : 'classic',
|
|
453
|
+
...config.svgr,
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
],
|
|
457
|
+
}
|
|
458
|
+
: {
|
|
459
|
+
type: 'asset',
|
|
460
|
+
parser: {
|
|
461
|
+
dataUrlCondition: {
|
|
462
|
+
maxSize: imagesSizeLimit,
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
generator: {
|
|
466
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
467
|
+
publicPath: isEnvProduction ? '../' : undefined,
|
|
468
|
+
},
|
|
469
|
+
}),
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function createAssetsRules({ isEnvProduction, config }) {
|
|
473
|
+
const imagesRule = {
|
|
474
|
+
test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
|
|
475
|
+
include: [paths_1.default.appClient, ...(config.images || [])],
|
|
476
|
+
type: 'asset',
|
|
477
|
+
parser: {
|
|
478
|
+
dataUrlCondition: {
|
|
479
|
+
maxSize: imagesSizeLimit,
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
generator: {
|
|
483
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
const fontsRule = {
|
|
487
|
+
test: /\.(ttf|eot|woff2?)$/,
|
|
488
|
+
include: [paths_1.default.appClient],
|
|
489
|
+
type: 'asset',
|
|
490
|
+
parser: {
|
|
491
|
+
dataUrlCondition: {
|
|
492
|
+
maxSize: fontSizeLimit,
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
generator: {
|
|
496
|
+
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
const rules = [imagesRule, fontsRule];
|
|
500
|
+
if (isEnvProduction) {
|
|
501
|
+
// with dynamic public path, imports from css files will look for assets in 'css/assets' directory
|
|
502
|
+
// we are enforcing loading them from 'assets'
|
|
503
|
+
rules.unshift({
|
|
504
|
+
test: /\.(ico|bmp|gif|jpe?g|png|svg)$/,
|
|
505
|
+
issuer: /\.s?css$/,
|
|
506
|
+
include: [paths_1.default.appClient, ...(config.images || [])],
|
|
507
|
+
type: 'asset',
|
|
508
|
+
parser: {
|
|
509
|
+
dataUrlCondition: {
|
|
510
|
+
maxSize: imagesSizeLimit,
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
generator: {
|
|
514
|
+
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
515
|
+
publicPath: '../',
|
|
516
|
+
},
|
|
517
|
+
}, {
|
|
518
|
+
test: /\.(ttf|eot|woff2?)$/,
|
|
519
|
+
issuer: /\.s?css$/,
|
|
520
|
+
include: [paths_1.default.appClient],
|
|
521
|
+
type: 'asset',
|
|
522
|
+
parser: {
|
|
523
|
+
dataUrlCondition: {
|
|
524
|
+
maxSize: fontSizeLimit,
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
generator: {
|
|
528
|
+
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
529
|
+
publicPath: '../',
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
return rules;
|
|
534
|
+
}
|
|
535
|
+
function createFallbackRules({ isEnvProduction }) {
|
|
536
|
+
const rules = [
|
|
537
|
+
{
|
|
538
|
+
type: 'asset/resource',
|
|
539
|
+
generator: {
|
|
540
|
+
filename: 'assets/[name].[contenthash:8][ext]',
|
|
541
|
+
},
|
|
542
|
+
exclude: [/\.[jt]sx?$/, /\.json$/, /\.[cm]js$/, /\.ejs$/],
|
|
543
|
+
},
|
|
544
|
+
];
|
|
545
|
+
if (isEnvProduction) {
|
|
546
|
+
// with dynamic public path, imports from css files will look for assets in 'css/assets' directory
|
|
547
|
+
// we are enforcing loading them from 'assets'
|
|
548
|
+
rules.unshift({
|
|
549
|
+
test: /\.(ttf|eot|woff2?|bmp|gif|jpe?g|png|svg)$/,
|
|
550
|
+
issuer: /\.s?css$/,
|
|
551
|
+
type: 'asset/resource',
|
|
552
|
+
generator: {
|
|
553
|
+
filename: 'assets/[name].[contenthash:8][ext]',
|
|
554
|
+
publicPath: '../',
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return rules;
|
|
559
|
+
}
|
|
560
|
+
/*
|
|
561
|
+
TODO
|
|
562
|
+
function createMomentTimezoneDataPlugin(options: NormalizedClientConfig['momentTz'] = {}) {
|
|
563
|
+
const currentYear = new Date().getFullYear();
|
|
564
|
+
// By default get data for current year only
|
|
565
|
+
// https://momentjs.com/timezone/docs/#/use-it/webpack/
|
|
566
|
+
const startYear = options.startYear ?? currentYear;
|
|
567
|
+
const endYear = options.endYear ?? currentYear;
|
|
568
|
+
|
|
569
|
+
return new MomentTimezoneDataPlugin({...options, startYear, endYear});
|
|
570
|
+
}
|
|
571
|
+
*/
|
|
572
|
+
function configurePlugins(options) {
|
|
573
|
+
const { isEnvDevelopment, isEnvProduction, config } = options;
|
|
574
|
+
const excludeFromClean = config.excludeFromClean || [];
|
|
575
|
+
const manifestFile = 'assets-manifest.json';
|
|
576
|
+
const plugins = [
|
|
577
|
+
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
578
|
+
verbose: config.verbose,
|
|
579
|
+
cleanOnceBeforeBuildPatterns: [
|
|
580
|
+
'**/*',
|
|
581
|
+
...(isEnvDevelopment ? ['!manifest.json'] : []),
|
|
582
|
+
...excludeFromClean,
|
|
583
|
+
],
|
|
584
|
+
}),
|
|
585
|
+
/*
|
|
586
|
+
new RspackManifestPlugin({
|
|
587
|
+
writeToFileEmit: true,
|
|
588
|
+
publicPath: '',
|
|
589
|
+
}),
|
|
590
|
+
*/
|
|
591
|
+
new rspack_manifest_plugin_1.RspackManifestPlugin({
|
|
592
|
+
fileName: isEnvProduction ? manifestFile : path.resolve(paths_1.default.appBuild, manifestFile),
|
|
593
|
+
writeToFileEmit: true,
|
|
594
|
+
useLegacyEmit: true,
|
|
595
|
+
publicPath: '',
|
|
596
|
+
generate: exports.generateManifest,
|
|
597
|
+
}),
|
|
598
|
+
new core_1.rspack.DefinePlugin({
|
|
599
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
600
|
+
...config.definitions,
|
|
601
|
+
}),
|
|
602
|
+
];
|
|
603
|
+
if (options.logger) {
|
|
604
|
+
plugins.push(new progress_plugin_1.ProgressPlugin({ logger: options.logger }));
|
|
605
|
+
}
|
|
606
|
+
// TODO use rspack tracing
|
|
607
|
+
// if (process.env.WEBPACK_PROFILE === 'true') {
|
|
608
|
+
// plugins.push(new webpack.debug.ProfilingPlugin());
|
|
609
|
+
// }
|
|
610
|
+
if (config.forkTsChecker !== false) {
|
|
611
|
+
plugins.push(new ts_checker_rspack_plugin_1.TsCheckerRspackPlugin({
|
|
612
|
+
...config.forkTsChecker,
|
|
613
|
+
typescript: {
|
|
614
|
+
typescriptPath: (0, utils_1.resolveTypescript)(),
|
|
615
|
+
configFile: path.resolve(paths_1.default.appClient, 'tsconfig.json'),
|
|
616
|
+
diagnosticOptions: {
|
|
617
|
+
syntactic: true,
|
|
618
|
+
},
|
|
619
|
+
mode: 'write-references',
|
|
620
|
+
...config.forkTsChecker?.typescript,
|
|
621
|
+
},
|
|
622
|
+
}));
|
|
623
|
+
}
|
|
624
|
+
if (config.detectCircularDependencies) {
|
|
625
|
+
let circularPluginOptions = {
|
|
626
|
+
exclude: /node_modules/,
|
|
627
|
+
allowAsyncCycles: true,
|
|
628
|
+
};
|
|
629
|
+
if (typeof config.detectCircularDependencies === 'object') {
|
|
630
|
+
circularPluginOptions = config.detectCircularDependencies;
|
|
631
|
+
}
|
|
632
|
+
plugins.push(new circular_dependency_plugin_1.default(circularPluginOptions));
|
|
633
|
+
}
|
|
634
|
+
if (isEnvProduction) {
|
|
635
|
+
if (config.analyzeBundle === 'true') {
|
|
636
|
+
plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
|
|
637
|
+
openAnalyzer: false,
|
|
638
|
+
analyzerMode: 'static',
|
|
639
|
+
reportFilename: 'stats.html',
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (config.monaco) {
|
|
644
|
+
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
645
|
+
plugins.push(new MonacoEditorWebpackPlugin({
|
|
646
|
+
filename: isEnvProduction ? '[name].[hash:8].worker.js' : undefined,
|
|
647
|
+
...config.monaco,
|
|
648
|
+
// currently, workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
649
|
+
// service instead
|
|
650
|
+
publicPath: path.normalize(config.publicPathPrefix + '/build/'),
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
const contextReplacement = config.contextReplacement || {};
|
|
654
|
+
//plugins.push(createMomentTimezoneDataPlugin(config.momentTz));
|
|
655
|
+
plugins.push(new core_1.ContextReplacementPlugin(/moment[\\/]locale$/,
|
|
656
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
657
|
+
new RegExp(`^\\./(${(contextReplacement.locale || ['ru']).join('|')})$`)));
|
|
658
|
+
plugins.push(new core_1.ContextReplacementPlugin(/dayjs[\\/]locale$/,
|
|
659
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
660
|
+
new RegExp(`^\\./(${(contextReplacement.locale || ['ru']).join('|')})\\.js$`)));
|
|
661
|
+
if (contextReplacement['highlight.js']) {
|
|
662
|
+
plugins.push(new core_1.ContextReplacementPlugin(/highlight\.js[\\/]lib[\\/]languages$/,
|
|
663
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
664
|
+
new RegExp(`^\\./(${contextReplacement['highlight.js'].join('|')})$`)));
|
|
665
|
+
}
|
|
666
|
+
if (isEnvDevelopment && config.reactRefresh !== false) {
|
|
667
|
+
const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`) } = config.devServer || {};
|
|
668
|
+
const { overlay, ...reactRefreshConfig } = config.reactRefresh({
|
|
669
|
+
overlay: { sockPath: webSocketPath },
|
|
670
|
+
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
671
|
+
});
|
|
672
|
+
plugins.push(new plugin_react_refresh_1.default({
|
|
673
|
+
...reactRefreshConfig,
|
|
674
|
+
overlay: typeof overlay === 'object'
|
|
675
|
+
? {
|
|
676
|
+
entry: typeof overlay.entry === 'string' ? overlay.entry : undefined,
|
|
677
|
+
module: typeof overlay.module === 'string' ? overlay.module : undefined,
|
|
678
|
+
sockPath: overlay.sockPath,
|
|
679
|
+
sockHost: overlay.sockHost,
|
|
680
|
+
sockPort: overlay.sockPort?.toString(),
|
|
681
|
+
sockProtocol: overlay.sockProtocol,
|
|
682
|
+
sockIntegration: overlay.sockIntegration === 'wds' ? 'wds' : undefined,
|
|
683
|
+
}
|
|
684
|
+
: undefined,
|
|
685
|
+
}));
|
|
686
|
+
}
|
|
687
|
+
if (config.polyfill?.process) {
|
|
688
|
+
plugins.push(new core_1.rspack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
689
|
+
}
|
|
690
|
+
if (isEnvProduction) {
|
|
691
|
+
plugins.push(new core_1.CssExtractRspackPlugin({
|
|
692
|
+
filename: 'css/[name].[contenthash:8].css',
|
|
693
|
+
chunkFilename: 'css/[name].[contenthash:8].chunk.css',
|
|
694
|
+
ignoreOrder: true,
|
|
695
|
+
}));
|
|
696
|
+
if (config.sentryConfig) {
|
|
697
|
+
const sentryPlugin = require('@sentry/webpack-plugin').sentryWebpackPlugin;
|
|
698
|
+
plugins.push(sentryPlugin({ ...config.sentryConfig }));
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (config.cdn) {
|
|
702
|
+
plugins.push(...(0, s3_upload_1.createS3UploadPlugins)(config, options.logger));
|
|
703
|
+
}
|
|
704
|
+
return plugins;
|
|
705
|
+
}
|
|
706
|
+
function configureOptimization({ config }) {
|
|
707
|
+
const configVendors = config.vendors ?? [];
|
|
708
|
+
let vendorsList = [
|
|
709
|
+
'react',
|
|
710
|
+
'react-dom',
|
|
711
|
+
'prop-types',
|
|
712
|
+
'redux',
|
|
713
|
+
'react-redux',
|
|
714
|
+
'@reduxjs/toolkit',
|
|
715
|
+
'lodash',
|
|
716
|
+
'lodash-es',
|
|
717
|
+
'moment',
|
|
718
|
+
'bem-cn-lite',
|
|
719
|
+
'axios',
|
|
720
|
+
];
|
|
721
|
+
if (typeof configVendors === 'function') {
|
|
722
|
+
vendorsList = configVendors(vendorsList);
|
|
723
|
+
}
|
|
724
|
+
else if (Array.isArray(configVendors)) {
|
|
725
|
+
vendorsList = vendorsList.concat(configVendors);
|
|
726
|
+
}
|
|
727
|
+
const useVendorsList = vendorsList.length > 0;
|
|
728
|
+
const optimization = {
|
|
729
|
+
splitChunks: {
|
|
730
|
+
chunks: 'all',
|
|
731
|
+
cacheGroups: {
|
|
732
|
+
...(useVendorsList
|
|
733
|
+
? {
|
|
734
|
+
defaultVendors: {
|
|
735
|
+
name: 'vendors',
|
|
736
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
737
|
+
test: new RegExp(`([\\\\/])node_modules\\1(${vendorsList.join('|')})\\1`),
|
|
738
|
+
priority: Infinity,
|
|
739
|
+
},
|
|
740
|
+
}
|
|
741
|
+
: undefined),
|
|
742
|
+
css: {
|
|
743
|
+
type: 'css/mini-extract',
|
|
744
|
+
enforce: true,
|
|
745
|
+
minChunks: 2,
|
|
746
|
+
reuseExistingChunk: true,
|
|
747
|
+
},
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
runtimeChunk: 'single',
|
|
751
|
+
minimizer: [
|
|
752
|
+
new core_1.rspack.SwcJsMinimizerRspackPlugin({
|
|
753
|
+
minimizerOptions: {
|
|
754
|
+
mangle: !config.reactProfiling,
|
|
755
|
+
compress: {
|
|
756
|
+
passes: 2,
|
|
757
|
+
},
|
|
758
|
+
format: {
|
|
759
|
+
safari10: config.safari10,
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
}),
|
|
763
|
+
new core_1.rspack.LightningCssMinimizerRspackPlugin({
|
|
764
|
+
minimizerOptions: {
|
|
765
|
+
// Plugin will read the browserslist itself and generate targets
|
|
766
|
+
targets: [],
|
|
767
|
+
},
|
|
768
|
+
}),
|
|
769
|
+
],
|
|
770
|
+
};
|
|
771
|
+
return optimization;
|
|
772
|
+
}
|