@gravity-ui/app-builder 0.15.1-beta.1 → 0.15.1-beta.3
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/dev/client.js +12 -5
- package/dist/common/models/index.d.ts +1 -1
- package/dist/common/webpack/compile.js +6 -3
- package/dist/common/webpack/config.js +37 -8
- package/dist/common/webpack/rspack.d.ts +11 -0
- package/dist/common/webpack/rspack.js +81 -2
- package/dist/create-cli.d.ts +4 -4
- package/dist/create-cli.js +1 -1
- package/package.json +3 -1
|
@@ -74,9 +74,6 @@ async function buildDevServer(config) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
else {
|
|
77
|
-
if (isSsr) {
|
|
78
|
-
throw new Error(`SSR is not supported in ${bundler}`);
|
|
79
|
-
}
|
|
80
77
|
rspackConfigs = [
|
|
81
78
|
await (0, config_1.rspackConfigFactory)({
|
|
82
79
|
webpackMode: "development" /* WebpackMode.Dev */,
|
|
@@ -84,6 +81,15 @@ async function buildDevServer(config) {
|
|
|
84
81
|
logger,
|
|
85
82
|
}),
|
|
86
83
|
];
|
|
84
|
+
if (isSsr) {
|
|
85
|
+
const ssrLogger = new logger_1.Logger('rspack(SSR)', config.verbose);
|
|
86
|
+
rspackConfigs.push(await (0, config_1.rspackConfigFactory)({
|
|
87
|
+
webpackMode: "development" /* WebpackMode.Dev */,
|
|
88
|
+
config: normalizedConfig,
|
|
89
|
+
logger: ssrLogger,
|
|
90
|
+
isSsr,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
87
93
|
}
|
|
88
94
|
const publicPath = path.normalize(config.client.publicPathPrefix + '/build/');
|
|
89
95
|
const staticFolder = path.resolve(paths_1.default.appDist, 'public');
|
|
@@ -163,8 +169,9 @@ async function buildDevServer(config) {
|
|
|
163
169
|
options.proxy = proxy;
|
|
164
170
|
let server;
|
|
165
171
|
if (bundler === 'rspack') {
|
|
166
|
-
// Rspack multicompiler dont work with lazy compilation
|
|
167
|
-
|
|
172
|
+
// Rspack multicompiler dont work with lazy compilation.
|
|
173
|
+
// Pass a single config to avoid multicompiler when SSR disabled.
|
|
174
|
+
const compiler = (0, core_1.rspack)(isSsr ? rspackConfigs : rspackConfigs[0]);
|
|
168
175
|
server = new dev_server_1.RspackDevServer(options, compiler);
|
|
169
176
|
// Need to clean cache before start. https://github.com/web-infra-dev/rspack/issues/9025
|
|
170
177
|
(0, rspack_1.clearCacheDirectory)(rspackConfigs[0], logger);
|
|
@@ -128,7 +128,7 @@ export interface ClientConfig {
|
|
|
128
128
|
svgr?: SvgrConfig;
|
|
129
129
|
entryFilter?: string[];
|
|
130
130
|
excludeFromClean?: string[];
|
|
131
|
-
analyzeBundle?: 'true' | 'statoscope';
|
|
131
|
+
analyzeBundle?: 'true' | 'statoscope' | 'rsdoctor';
|
|
132
132
|
statoscopeConfig?: Partial<StatoscopeOptions>;
|
|
133
133
|
reactProfiling?: boolean;
|
|
134
134
|
/**
|
|
@@ -9,6 +9,7 @@ const core_1 = require("@rspack/core");
|
|
|
9
9
|
const logger_1 = require("../logger");
|
|
10
10
|
const config_1 = require("./config");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
+
const rspack_1 = require("./rspack");
|
|
12
13
|
async function clientCompile(config) {
|
|
13
14
|
const logger = new logger_1.Logger('client', config.verbose);
|
|
14
15
|
const webpackConfigs = [];
|
|
@@ -41,17 +42,19 @@ async function clientCompile(config) {
|
|
|
41
42
|
logger.verbose('Config created');
|
|
42
43
|
return new Promise((resolve) => {
|
|
43
44
|
const compiler = config.bundler === 'rspack'
|
|
44
|
-
? (0, core_1.rspack)(rspackConfigs)
|
|
45
|
+
? (0, core_1.rspack)(rspackConfigs, (0, rspack_1.rspackCompilerHandlerFactory)(logger, async () => {
|
|
46
|
+
resolve();
|
|
47
|
+
}))
|
|
45
48
|
: (0, webpack_1.default)(webpackConfigs, (0, utils_1.webpackCompilerHandlerFactory)(logger, async () => {
|
|
46
49
|
resolve();
|
|
47
50
|
}));
|
|
48
51
|
process.on('SIGINT', async () => {
|
|
49
|
-
compiler
|
|
52
|
+
compiler?.close(() => {
|
|
50
53
|
process.exit(1);
|
|
51
54
|
});
|
|
52
55
|
});
|
|
53
56
|
process.on('SIGTERM', async () => {
|
|
54
|
-
compiler
|
|
57
|
+
compiler?.close(() => {
|
|
55
58
|
process.exit(1);
|
|
56
59
|
});
|
|
57
60
|
});
|
|
@@ -74,10 +74,7 @@ function getHelperOptions({ webpackMode, config, logger, isSsr = false, }) {
|
|
|
74
74
|
isSsr,
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
const { config } = options;
|
|
79
|
-
const helperOptions = getHelperOptions(options);
|
|
80
|
-
const { isSsr, isEnvProduction } = helperOptions;
|
|
77
|
+
function configureExternals({ config, isSsr }) {
|
|
81
78
|
let externals = config.externals;
|
|
82
79
|
if (isSsr) {
|
|
83
80
|
externals =
|
|
@@ -88,6 +85,24 @@ async function webpackConfigFactory(options) {
|
|
|
88
85
|
module: config.ssr?.moduleType === 'esm',
|
|
89
86
|
});
|
|
90
87
|
}
|
|
88
|
+
return externals;
|
|
89
|
+
}
|
|
90
|
+
function prepareRspackExternals(externals) {
|
|
91
|
+
if (Array.isArray(externals)) {
|
|
92
|
+
const rspackExternals = {};
|
|
93
|
+
for (const ext of externals) {
|
|
94
|
+
if (typeof ext === 'object' && ext !== null) {
|
|
95
|
+
Object.assign(rspackExternals, ext);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return rspackExternals;
|
|
99
|
+
}
|
|
100
|
+
return externals;
|
|
101
|
+
}
|
|
102
|
+
async function webpackConfigFactory(options) {
|
|
103
|
+
const { config } = options;
|
|
104
|
+
const helperOptions = getHelperOptions(options);
|
|
105
|
+
const { isSsr, isEnvProduction } = helperOptions;
|
|
91
106
|
let webpackConfig = {
|
|
92
107
|
mode: isEnvProduction ? 'production' : 'development',
|
|
93
108
|
context: paths_1.default.app,
|
|
@@ -102,7 +117,7 @@ async function webpackConfigFactory(options) {
|
|
|
102
117
|
},
|
|
103
118
|
plugins: configureWebpackPlugins(helperOptions),
|
|
104
119
|
optimization: configureOptimization(helperOptions),
|
|
105
|
-
externals,
|
|
120
|
+
externals: configureExternals(helperOptions),
|
|
106
121
|
node: config.node,
|
|
107
122
|
watchOptions: configureWatchOptions(helperOptions),
|
|
108
123
|
ignoreWarnings: [/Failed to parse source map/],
|
|
@@ -147,7 +162,7 @@ async function rspackConfigFactory(options) {
|
|
|
147
162
|
},
|
|
148
163
|
plugins: configureRspackPlugins(helperOptions),
|
|
149
164
|
optimization: configureRspackOptimization(helperOptions),
|
|
150
|
-
|
|
165
|
+
externals: prepareRspackExternals(configureExternals(helperOptions)),
|
|
151
166
|
node: config.node,
|
|
152
167
|
watchOptions: configureWatchOptions(helperOptions),
|
|
153
168
|
ignoreWarnings: [/Failed to parse source map/],
|
|
@@ -774,7 +789,6 @@ function configureCommonPlugins(options) {
|
|
|
774
789
|
...excludeFromClean,
|
|
775
790
|
],
|
|
776
791
|
}),
|
|
777
|
-
...(options.logger ? [new progress_plugin_1.ProgressPlugin({ logger: options.logger })] : []),
|
|
778
792
|
];
|
|
779
793
|
if (config.detectCircularDependencies) {
|
|
780
794
|
let circularPluginOptions = {
|
|
@@ -824,6 +838,7 @@ function configureWebpackPlugins(options) {
|
|
|
824
838
|
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
825
839
|
const webpackPlugins = [
|
|
826
840
|
...configureCommonPlugins(options),
|
|
841
|
+
...(options.logger ? [new progress_plugin_1.ProgressPlugin({ logger: options.logger })] : []),
|
|
827
842
|
new webpack.DefinePlugin(getDefinitions(options)),
|
|
828
843
|
new webpack_manifest_plugin_1.WebpackManifestPlugin({
|
|
829
844
|
writeToFileEmit: true,
|
|
@@ -858,6 +873,12 @@ function configureWebpackPlugins(options) {
|
|
|
858
873
|
...customStatoscopeConfig,
|
|
859
874
|
}));
|
|
860
875
|
}
|
|
876
|
+
if (config.analyzeBundle === 'rsdoctor') {
|
|
877
|
+
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
878
|
+
webpackPlugins.push(new RsdoctorWebpackPlugin({
|
|
879
|
+
mode: 'brief',
|
|
880
|
+
}));
|
|
881
|
+
}
|
|
861
882
|
}
|
|
862
883
|
if (!isSsr) {
|
|
863
884
|
const contextReplacements = getContextReplacements(options);
|
|
@@ -881,6 +902,7 @@ function configureRspackPlugins(options) {
|
|
|
881
902
|
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
882
903
|
const rspackPlugins = [
|
|
883
904
|
...configureCommonPlugins(options),
|
|
905
|
+
...(options.logger ? [new rspack_1.RspackProgressPlugin({ logger: options.logger })] : []),
|
|
884
906
|
new core_1.rspack.DefinePlugin(getDefinitions(options)),
|
|
885
907
|
new rspack_manifest_plugin_1.RspackManifestPlugin({
|
|
886
908
|
fileName: isEnvProduction
|
|
@@ -896,7 +918,14 @@ function configureRspackPlugins(options) {
|
|
|
896
918
|
if (isEnvProduction || isSsr || config.ssr) {
|
|
897
919
|
rspackPlugins.push(new core_1.CssExtractRspackPlugin(getCssExtractPluginOptions(options)));
|
|
898
920
|
}
|
|
899
|
-
|
|
921
|
+
if (isEnvProduction) {
|
|
922
|
+
if (config.analyzeBundle === 'rsdoctor') {
|
|
923
|
+
const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
|
|
924
|
+
rspackPlugins.push(new RsdoctorRspackPlugin({
|
|
925
|
+
mode: 'brief',
|
|
926
|
+
}));
|
|
927
|
+
}
|
|
928
|
+
}
|
|
900
929
|
if (!isSsr) {
|
|
901
930
|
const contextReplacements = getContextReplacements(options);
|
|
902
931
|
contextReplacements.forEach(({ resourceRegExp, newResource }) => rspackPlugins.push(new core_1.rspack.ContextReplacementPlugin(resourceRegExp, newResource)));
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { ManifestPluginOptions } from 'rspack-manifest-plugin';
|
|
2
2
|
import type { RuleSetRule as WebpackRuleSetRule } from 'webpack';
|
|
3
|
+
import { Compiler, MultiStats, rspack } from '@rspack/core';
|
|
3
4
|
import type { Configuration, RuleSetRule as RspackRuleSetRule } from '@rspack/core';
|
|
4
5
|
import type { Logger } from '../logger';
|
|
5
6
|
export declare function clearCacheDirectory(config: Configuration, logger: Logger): void;
|
|
6
7
|
export declare const generateAssetsManifest: ManifestPluginOptions['generate'];
|
|
7
8
|
export declare function prepareRspackRules(webpackRules: (undefined | null | false | '' | 0 | WebpackRuleSetRule | '...')[]): (RspackRuleSetRule | '...')[];
|
|
9
|
+
export declare class RspackProgressPlugin extends rspack.ProgressPlugin {
|
|
10
|
+
private _logger;
|
|
11
|
+
private _state;
|
|
12
|
+
constructor({ logger }: {
|
|
13
|
+
logger: Logger;
|
|
14
|
+
});
|
|
15
|
+
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
16
|
+
apply(compiler: Compiler): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function rspackCompilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error | null, stats?: MultiStats) => Promise<void>;
|
|
@@ -26,11 +26,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.generateAssetsManifest = void 0;
|
|
29
|
+
exports.RspackProgressPlugin = exports.generateAssetsManifest = void 0;
|
|
30
30
|
exports.clearCacheDirectory = clearCacheDirectory;
|
|
31
31
|
exports.prepareRspackRules = prepareRspackRules;
|
|
32
|
+
exports.rspackCompilerHandlerFactory = rspackCompilerHandlerFactory;
|
|
33
|
+
const core_1 = require("@rspack/core");
|
|
32
34
|
const fs = __importStar(require("node:fs"));
|
|
33
35
|
const path = __importStar(require("node:path"));
|
|
36
|
+
const pretty_time_1 = require("../logger/pretty-time");
|
|
34
37
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
35
38
|
function clearCacheDirectory(config, logger) {
|
|
36
39
|
if (!config.cache) {
|
|
@@ -64,7 +67,7 @@ const generateAssetsManifest = (seed, files, entries) => {
|
|
|
64
67
|
};
|
|
65
68
|
}, {});
|
|
66
69
|
return {
|
|
67
|
-
|
|
70
|
+
...manifestFiles,
|
|
68
71
|
entrypoints,
|
|
69
72
|
};
|
|
70
73
|
};
|
|
@@ -109,3 +112,79 @@ function prepareRspackRules(webpackRules) {
|
|
|
109
112
|
}
|
|
110
113
|
return rspackRules;
|
|
111
114
|
}
|
|
115
|
+
class RspackProgressPlugin extends core_1.rspack.ProgressPlugin {
|
|
116
|
+
_logger;
|
|
117
|
+
_state = {};
|
|
118
|
+
constructor({ logger }) {
|
|
119
|
+
super();
|
|
120
|
+
this._logger = logger;
|
|
121
|
+
}
|
|
122
|
+
handler = (percent, message, ...details) => {
|
|
123
|
+
const progress = Math.floor(percent * 100);
|
|
124
|
+
this._logger.status(`${this._logger.colors.green(`${progress}%`)} - ${this._logger.colors.yellow(message)}${details.length > 0 ? `: ${this._logger.colors.dim(...details)}` : ''}`);
|
|
125
|
+
};
|
|
126
|
+
apply(compiler) {
|
|
127
|
+
super.apply(compiler);
|
|
128
|
+
hook(compiler, 'compile', () => {
|
|
129
|
+
this._logger.message('Start compilation');
|
|
130
|
+
this._logger.message(`rspack v${compiler.rspack.rspackVersion}`);
|
|
131
|
+
this._state.start = process.hrtime.bigint();
|
|
132
|
+
});
|
|
133
|
+
hook(compiler, 'invalid', (fileName, changeTime) => {
|
|
134
|
+
this._logger.verbose(`Invalidate file: ${fileName} at ${changeTime}`);
|
|
135
|
+
});
|
|
136
|
+
hook(compiler, 'done', (stats) => {
|
|
137
|
+
const time = this._state.start ? ' in ' + (0, pretty_time_1.elapsedTime)(this._state.start) : '';
|
|
138
|
+
const hasErrors = stats.hasErrors();
|
|
139
|
+
if (hasErrors) {
|
|
140
|
+
this._logger.error('Compiled with some errors' + time);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
this._logger.success('Compiled successfully' + time);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.RspackProgressPlugin = RspackProgressPlugin;
|
|
149
|
+
function hook(compiler, hookName, callback) {
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
compiler.hooks[hookName].tap(`app-builder: ${hookName}`, callback);
|
|
152
|
+
}
|
|
153
|
+
function rspackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
154
|
+
return async (err, stats) => {
|
|
155
|
+
if (err) {
|
|
156
|
+
logger.panic(err.message, err);
|
|
157
|
+
}
|
|
158
|
+
if (stats) {
|
|
159
|
+
logger.message('Stats:\n' +
|
|
160
|
+
stats.toString({
|
|
161
|
+
preset: 'errors-warnings',
|
|
162
|
+
colors: process.stdout.isTTY,
|
|
163
|
+
assets: logger.isVerbose,
|
|
164
|
+
modules: logger.isVerbose,
|
|
165
|
+
entrypoints: logger.isVerbose,
|
|
166
|
+
timings: logger.isVerbose,
|
|
167
|
+
}));
|
|
168
|
+
if (stats.hasErrors()) {
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (onCompilationEnd) {
|
|
173
|
+
await onCompilationEnd();
|
|
174
|
+
}
|
|
175
|
+
const [clientStats, ssrStats] = stats?.stats ?? [];
|
|
176
|
+
if (clientStats) {
|
|
177
|
+
const { startTime = 0, endTime = 0 } = clientStats;
|
|
178
|
+
const time = endTime - startTime;
|
|
179
|
+
logger.success(`Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1_000_000))}`);
|
|
180
|
+
}
|
|
181
|
+
if (ssrStats) {
|
|
182
|
+
const { startTime = 0, endTime = 0 } = ssrStats;
|
|
183
|
+
const time = endTime - startTime;
|
|
184
|
+
logger.success(`SSR: Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1_000_000))}`);
|
|
185
|
+
}
|
|
186
|
+
if (!clientStats && !ssrStats) {
|
|
187
|
+
logger.success(`Client was successfully compiled`);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
package/dist/create-cli.d.ts
CHANGED
|
@@ -19,8 +19,8 @@ export declare function createCli(argv: string[]): {
|
|
|
19
19
|
"lazy-compilation": boolean | undefined;
|
|
20
20
|
reactProfiling: boolean | undefined;
|
|
21
21
|
"react-profiling": boolean | undefined;
|
|
22
|
-
analyzeBundle: "true" | "statoscope" | undefined;
|
|
23
|
-
"analyze-bundle": "true" | "statoscope" | undefined;
|
|
22
|
+
analyzeBundle: "true" | "statoscope" | "rsdoctor" | undefined;
|
|
23
|
+
"analyze-bundle": "true" | "statoscope" | "rsdoctor" | undefined;
|
|
24
24
|
disableSourceMapGeneration: boolean | undefined;
|
|
25
25
|
"disable-source-map-generation": boolean | undefined;
|
|
26
26
|
"debug-webpack": boolean | undefined;
|
|
@@ -47,8 +47,8 @@ export declare function createCli(argv: string[]): {
|
|
|
47
47
|
"lazy-compilation": boolean | undefined;
|
|
48
48
|
reactProfiling: boolean | undefined;
|
|
49
49
|
"react-profiling": boolean | undefined;
|
|
50
|
-
analyzeBundle: "true" | "statoscope" | undefined;
|
|
51
|
-
"analyze-bundle": "true" | "statoscope" | undefined;
|
|
50
|
+
analyzeBundle: "true" | "statoscope" | "rsdoctor" | undefined;
|
|
51
|
+
"analyze-bundle": "true" | "statoscope" | "rsdoctor" | undefined;
|
|
52
52
|
disableSourceMapGeneration: boolean | undefined;
|
|
53
53
|
"disable-source-map-generation": boolean | undefined;
|
|
54
54
|
"debug-webpack": boolean | undefined;
|
package/dist/create-cli.js
CHANGED
|
@@ -176,7 +176,7 @@ function createCli(argv) {
|
|
|
176
176
|
.option('analyze-bundle', {
|
|
177
177
|
group: 'Client',
|
|
178
178
|
describe: 'Analyze bundle',
|
|
179
|
-
choices: ['true', 'statoscope'],
|
|
179
|
+
choices: ['true', 'statoscope', 'rsdoctor'],
|
|
180
180
|
})
|
|
181
181
|
.option('disable-fork-ts-checker', {
|
|
182
182
|
group: 'Client',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.15.1-beta.
|
|
3
|
+
"version": "0.15.1-beta.3",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -70,6 +70,8 @@
|
|
|
70
70
|
"@babel/runtime": "^7.26.0",
|
|
71
71
|
"@okikio/sharedworker": "^1.0.7",
|
|
72
72
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
|
|
73
|
+
"@rsdoctor/rspack-plugin": "^0.4.13",
|
|
74
|
+
"@rsdoctor/webpack-plugin": "^0.4.13",
|
|
73
75
|
"@rspack/core": "^1.2.2",
|
|
74
76
|
"@rspack/dev-server": "^1.0.10",
|
|
75
77
|
"@rspack/plugin-react-refresh": "^1.0.0",
|