@gravity-ui/app-builder 0.15.1-beta.2 → 0.15.1-beta.4
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 +13 -6
- package/dist/common/library/index.js +0 -1
- package/dist/common/webpack/compile.js +5 -7
- package/dist/common/webpack/config.js +80 -81
- package/dist/common/webpack/progress-plugin.d.ts +24 -9
- package/dist/common/webpack/progress-plugin.js +42 -38
- package/dist/common/webpack/rspack.d.ts +0 -11
- package/dist/common/webpack/rspack.js +2 -81
- package/dist/common/webpack/utils.d.ts +2 -1
- package/dist/common/webpack/utils.js +2 -2
- package/package.json +1 -1
|
@@ -64,7 +64,7 @@ async function buildDevServer(config) {
|
|
|
64
64
|
}),
|
|
65
65
|
];
|
|
66
66
|
if (isSsr) {
|
|
67
|
-
const ssrLogger = new logger_1.Logger('
|
|
67
|
+
const ssrLogger = new logger_1.Logger('client(SSR)', config.verbose);
|
|
68
68
|
webpackConfigs.push(await (0, config_1.webpackConfigFactory)({
|
|
69
69
|
webpackMode: "development" /* WebpackMode.Dev */,
|
|
70
70
|
config: normalizedConfig,
|
|
@@ -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('client(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);
|
|
@@ -129,7 +129,6 @@ function compileStyles(inputDir, outputDir, onFinish, additionalGlobs = []) {
|
|
|
129
129
|
const sassTransformed = sass_1.default.compile(scssFile, {
|
|
130
130
|
sourceMap: true,
|
|
131
131
|
sourceMapIncludeSources: true,
|
|
132
|
-
silenceDeprecations: ['legacy-js-api'],
|
|
133
132
|
importers: [
|
|
134
133
|
{
|
|
135
134
|
findFileUrl(url) {
|
|
@@ -9,7 +9,6 @@ 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");
|
|
13
12
|
async function clientCompile(config) {
|
|
14
13
|
const logger = new logger_1.Logger('client', config.verbose);
|
|
15
14
|
const webpackConfigs = [];
|
|
@@ -41,13 +40,12 @@ async function clientCompile(config) {
|
|
|
41
40
|
}
|
|
42
41
|
logger.verbose('Config created');
|
|
43
42
|
return new Promise((resolve) => {
|
|
43
|
+
const compilerHandler = (0, utils_1.compilerHandlerFactory)(logger, async () => {
|
|
44
|
+
resolve();
|
|
45
|
+
});
|
|
44
46
|
const compiler = config.bundler === 'rspack'
|
|
45
|
-
? (0, core_1.rspack)(rspackConfigs,
|
|
46
|
-
|
|
47
|
-
}))
|
|
48
|
-
: (0, webpack_1.default)(webpackConfigs, (0, utils_1.webpackCompilerHandlerFactory)(logger, async () => {
|
|
49
|
-
resolve();
|
|
50
|
-
}));
|
|
47
|
+
? (0, core_1.rspack)(rspackConfigs, compilerHandler)
|
|
48
|
+
: (0, webpack_1.default)(webpackConfigs, compilerHandler);
|
|
51
49
|
process.on('SIGINT', async () => {
|
|
52
50
|
compiler?.close(() => {
|
|
53
51
|
process.exit(1);
|
|
@@ -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,12 @@ async function webpackConfigFactory(options) {
|
|
|
88
85
|
module: config.ssr?.moduleType === 'esm',
|
|
89
86
|
});
|
|
90
87
|
}
|
|
88
|
+
return externals;
|
|
89
|
+
}
|
|
90
|
+
async function webpackConfigFactory(options) {
|
|
91
|
+
const { config } = options;
|
|
92
|
+
const helperOptions = getHelperOptions(options);
|
|
93
|
+
const { isSsr, isEnvProduction } = helperOptions;
|
|
91
94
|
let webpackConfig = {
|
|
92
95
|
mode: isEnvProduction ? 'production' : 'development',
|
|
93
96
|
context: paths_1.default.app,
|
|
@@ -102,7 +105,7 @@ async function webpackConfigFactory(options) {
|
|
|
102
105
|
},
|
|
103
106
|
plugins: configureWebpackPlugins(helperOptions),
|
|
104
107
|
optimization: configureOptimization(helperOptions),
|
|
105
|
-
externals,
|
|
108
|
+
externals: configureExternals(helperOptions),
|
|
106
109
|
node: config.node,
|
|
107
110
|
watchOptions: configureWatchOptions(helperOptions),
|
|
108
111
|
ignoreWarnings: [/Failed to parse source map/],
|
|
@@ -140,14 +143,14 @@ async function rspackConfigFactory(options) {
|
|
|
140
143
|
target: isSsr ? 'node' : undefined,
|
|
141
144
|
devtool: configureDevTool(helperOptions),
|
|
142
145
|
entry: configureEntry(helperOptions),
|
|
143
|
-
output:
|
|
146
|
+
output: configureOutput(helperOptions),
|
|
144
147
|
resolve: configureRspackResolve(helperOptions),
|
|
145
148
|
module: {
|
|
146
149
|
rules: (0, rspack_1.prepareRspackRules)(configureModuleRules(helperOptions)),
|
|
147
150
|
},
|
|
148
151
|
plugins: configureRspackPlugins(helperOptions),
|
|
149
152
|
optimization: configureRspackOptimization(helperOptions),
|
|
150
|
-
|
|
153
|
+
externals: configureExternals(helperOptions),
|
|
151
154
|
node: config.node,
|
|
152
155
|
watchOptions: configureWatchOptions(helperOptions),
|
|
153
156
|
ignoreWarnings: [/Failed to parse source map/],
|
|
@@ -366,18 +369,6 @@ function configureOutput(options) {
|
|
|
366
369
|
...ssrOptions,
|
|
367
370
|
};
|
|
368
371
|
}
|
|
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
|
-
}
|
|
381
372
|
function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, isSsr, }) {
|
|
382
373
|
const plugins = [];
|
|
383
374
|
if (!isSsr) {
|
|
@@ -455,9 +446,7 @@ function createWorkerRule(options) {
|
|
|
455
446
|
loader: require.resolve('./worker/worker-loader'),
|
|
456
447
|
}
|
|
457
448
|
: {
|
|
458
|
-
loader: require.resolve(
|
|
459
|
-
? 'worker-rspack-loader'
|
|
460
|
-
: 'worker-loader'),
|
|
449
|
+
loader: require.resolve('worker-rspack-loader'),
|
|
461
450
|
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
462
451
|
// service instead
|
|
463
452
|
options: {
|
|
@@ -762,9 +751,28 @@ function getCssExtractPluginOptions({ isEnvProduction }) {
|
|
|
762
751
|
ignoreOrder: true,
|
|
763
752
|
};
|
|
764
753
|
}
|
|
754
|
+
const commonBundlerPlugins = {
|
|
755
|
+
DefinePlugin: {
|
|
756
|
+
rspack: core_1.rspack.DefinePlugin,
|
|
757
|
+
webpack: webpack.DefinePlugin,
|
|
758
|
+
},
|
|
759
|
+
ContextReplacementPlugin: {
|
|
760
|
+
rspack: core_1.rspack.ContextReplacementPlugin,
|
|
761
|
+
webpack: webpack.ContextReplacementPlugin,
|
|
762
|
+
},
|
|
763
|
+
ProvidePlugin: {
|
|
764
|
+
rspack: core_1.rspack.ProvidePlugin,
|
|
765
|
+
webpack: webpack.ProvidePlugin,
|
|
766
|
+
},
|
|
767
|
+
ProgressPlugin: {
|
|
768
|
+
rspack: progress_plugin_1.RspackProgressPlugin,
|
|
769
|
+
webpack: progress_plugin_1.WebpackProgressPlugin,
|
|
770
|
+
},
|
|
771
|
+
};
|
|
765
772
|
function configureCommonPlugins(options) {
|
|
766
773
|
const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
|
|
767
774
|
const excludeFromClean = config.excludeFromClean || [];
|
|
775
|
+
const bundler = config.bundler;
|
|
768
776
|
const plugins = [
|
|
769
777
|
new clean_webpack_plugin_1.CleanWebpackPlugin({
|
|
770
778
|
verbose: config.verbose,
|
|
@@ -774,6 +782,10 @@ function configureCommonPlugins(options) {
|
|
|
774
782
|
...excludeFromClean,
|
|
775
783
|
],
|
|
776
784
|
}),
|
|
785
|
+
new commonBundlerPlugins['DefinePlugin'][bundler](getDefinitions(options)),
|
|
786
|
+
...(options.logger
|
|
787
|
+
? [new commonBundlerPlugins['ProgressPlugin'][bundler]({ logger: options.logger })]
|
|
788
|
+
: []),
|
|
777
789
|
];
|
|
778
790
|
if (config.detectCircularDependencies) {
|
|
779
791
|
let circularPluginOptions = {
|
|
@@ -795,6 +807,13 @@ function configureCommonPlugins(options) {
|
|
|
795
807
|
}
|
|
796
808
|
}
|
|
797
809
|
if (!isSsr) {
|
|
810
|
+
const contextReplacements = getContextReplacements(options);
|
|
811
|
+
contextReplacements.forEach(({ resourceRegExp, newResource }) => plugins.push(new commonBundlerPlugins['ContextReplacementPlugin'][bundler](resourceRegExp, newResource)));
|
|
812
|
+
if (config.polyfill?.process) {
|
|
813
|
+
plugins.push(new commonBundlerPlugins['ProvidePlugin'][bundler]({
|
|
814
|
+
process: 'process/browser.js',
|
|
815
|
+
}));
|
|
816
|
+
}
|
|
798
817
|
if (config.monaco) {
|
|
799
818
|
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
800
819
|
plugins.push(new MonacoEditorWebpackPlugin({
|
|
@@ -808,6 +827,18 @@ function configureCommonPlugins(options) {
|
|
|
808
827
|
plugins.push(createMomentTimezoneDataPlugin(config.momentTz));
|
|
809
828
|
}
|
|
810
829
|
if (isEnvProduction) {
|
|
830
|
+
if (config.analyzeBundle === 'statoscope') {
|
|
831
|
+
const customStatoscopeConfig = config.statoscopeConfig || {};
|
|
832
|
+
plugins.push(new webpack_plugin_1.default({
|
|
833
|
+
saveReportTo: path.resolve(options.buildDirectory, 'report.html'),
|
|
834
|
+
saveStatsTo: path.resolve(options.buildDirectory, 'stats.json'),
|
|
835
|
+
open: false,
|
|
836
|
+
statsOptions: {
|
|
837
|
+
all: true,
|
|
838
|
+
},
|
|
839
|
+
...customStatoscopeConfig,
|
|
840
|
+
}));
|
|
841
|
+
}
|
|
811
842
|
if (config.sentryConfig) {
|
|
812
843
|
const sentryPlugin = require('@sentry/webpack-plugin').sentryWebpackPlugin;
|
|
813
844
|
plugins.push(sentryPlugin({ ...config.sentryConfig }));
|
|
@@ -823,8 +854,6 @@ function configureWebpackPlugins(options) {
|
|
|
823
854
|
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
824
855
|
const webpackPlugins = [
|
|
825
856
|
...configureCommonPlugins(options),
|
|
826
|
-
...(options.logger ? [new progress_plugin_1.ProgressPlugin({ logger: options.logger })] : []),
|
|
827
|
-
new webpack.DefinePlugin(getDefinitions(options)),
|
|
828
857
|
new webpack_manifest_plugin_1.WebpackManifestPlugin({
|
|
829
858
|
writeToFileEmit: true,
|
|
830
859
|
publicPath: '',
|
|
@@ -846,18 +875,6 @@ function configureWebpackPlugins(options) {
|
|
|
846
875
|
webpackPlugins.push(new mini_css_extract_plugin_1.default(getCssExtractPluginOptions(options)));
|
|
847
876
|
}
|
|
848
877
|
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
878
|
if (config.analyzeBundle === 'rsdoctor') {
|
|
862
879
|
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
|
|
863
880
|
webpackPlugins.push(new RsdoctorWebpackPlugin({
|
|
@@ -865,20 +882,13 @@ function configureWebpackPlugins(options) {
|
|
|
865
882
|
}));
|
|
866
883
|
}
|
|
867
884
|
}
|
|
868
|
-
if (!isSsr) {
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
876
|
-
});
|
|
877
|
-
webpackPlugins.push(new react_refresh_webpack_plugin_1.default(reactRefreshConfig));
|
|
878
|
-
}
|
|
879
|
-
if (config.polyfill?.process) {
|
|
880
|
-
webpackPlugins.push(new webpack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
881
|
-
}
|
|
885
|
+
if (!isSsr && isEnvDevelopment && config.reactRefresh !== false) {
|
|
886
|
+
const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`) } = config.devServer || {};
|
|
887
|
+
const reactRefreshConfig = config.reactRefresh({
|
|
888
|
+
overlay: { sockPath: webSocketPath },
|
|
889
|
+
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
890
|
+
});
|
|
891
|
+
webpackPlugins.push(new react_refresh_webpack_plugin_1.default(reactRefreshConfig));
|
|
882
892
|
}
|
|
883
893
|
return webpackPlugins;
|
|
884
894
|
}
|
|
@@ -887,8 +897,6 @@ function configureRspackPlugins(options) {
|
|
|
887
897
|
const forkTsCheckerOptions = getForkTsCheckerOptions(options);
|
|
888
898
|
const rspackPlugins = [
|
|
889
899
|
...configureCommonPlugins(options),
|
|
890
|
-
...(options.logger ? [new rspack_1.RspackProgressPlugin({ logger: options.logger })] : []),
|
|
891
|
-
new core_1.rspack.DefinePlugin(getDefinitions(options)),
|
|
892
900
|
new rspack_manifest_plugin_1.RspackManifestPlugin({
|
|
893
901
|
fileName: isEnvProduction
|
|
894
902
|
? assetsManifestFile
|
|
@@ -911,35 +919,26 @@ function configureRspackPlugins(options) {
|
|
|
911
919
|
}));
|
|
912
920
|
}
|
|
913
921
|
}
|
|
914
|
-
if (!isSsr) {
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
sockProtocol: overlay.sockProtocol,
|
|
935
|
-
sockIntegration: overlay.sockIntegration === 'wds' ? 'wds' : undefined,
|
|
936
|
-
}
|
|
937
|
-
: undefined,
|
|
938
|
-
}));
|
|
939
|
-
}
|
|
940
|
-
if (config.polyfill?.process) {
|
|
941
|
-
rspackPlugins.push(new core_1.rspack.ProvidePlugin({ process: 'process/browser.js' }));
|
|
942
|
-
}
|
|
922
|
+
if (!isSsr && isEnvDevelopment && config.reactRefresh !== false) {
|
|
923
|
+
const { webSocketPath = path.normalize(`/${config.publicPathPrefix}/build/sockjs-node`) } = config.devServer || {};
|
|
924
|
+
const { overlay, ...reactRefreshConfig } = config.reactRefresh({
|
|
925
|
+
overlay: { sockPath: webSocketPath },
|
|
926
|
+
exclude: [/node_modules/, /\.worker\.[jt]sx?$/],
|
|
927
|
+
});
|
|
928
|
+
rspackPlugins.push(new plugin_react_refresh_1.default({
|
|
929
|
+
...reactRefreshConfig,
|
|
930
|
+
overlay: typeof overlay === 'object'
|
|
931
|
+
? {
|
|
932
|
+
entry: typeof overlay.entry === 'string' ? overlay.entry : undefined,
|
|
933
|
+
module: typeof overlay.module === 'string' ? overlay.module : undefined,
|
|
934
|
+
sockPath: overlay.sockPath,
|
|
935
|
+
sockHost: overlay.sockHost,
|
|
936
|
+
sockPort: overlay.sockPort?.toString(),
|
|
937
|
+
sockProtocol: overlay.sockProtocol,
|
|
938
|
+
sockIntegration: overlay.sockIntegration === 'wds' ? 'wds' : undefined,
|
|
939
|
+
}
|
|
940
|
+
: undefined,
|
|
941
|
+
}));
|
|
943
942
|
}
|
|
944
943
|
return rspackPlugins;
|
|
945
944
|
}
|
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import webpack from 'webpack';
|
|
2
1
|
import type * as Webpack from 'webpack';
|
|
3
2
|
import type { Logger } from '../logger';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
constructor({ logger }: {
|
|
8
|
-
logger: Logger;
|
|
9
|
-
});
|
|
10
|
-
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
11
|
-
apply(compiler: Webpack.Compiler): void;
|
|
3
|
+
interface State {
|
|
4
|
+
done?: boolean;
|
|
5
|
+
start?: bigint;
|
|
12
6
|
}
|
|
7
|
+
export declare const WebpackProgressPlugin: {
|
|
8
|
+
new ({ logger }: {
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}): {
|
|
11
|
+
logger: Logger;
|
|
12
|
+
state: State;
|
|
13
|
+
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
14
|
+
apply(compiler: Webpack.Compiler): void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare const RspackProgressPlugin: {
|
|
18
|
+
new ({ logger }: {
|
|
19
|
+
logger: Logger;
|
|
20
|
+
}): {
|
|
21
|
+
logger: Logger;
|
|
22
|
+
state: State;
|
|
23
|
+
handler: (percent: number, message: string, ...details: string[]) => void;
|
|
24
|
+
apply(compiler: Webpack.Compiler): void;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -3,49 +3,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.RspackProgressPlugin = exports.WebpackProgressPlugin = void 0;
|
|
7
7
|
const webpack_1 = __importDefault(require("webpack"));
|
|
8
8
|
const pretty_time_1 = require("../logger/pretty-time");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
function createProgressPlugin(BaseClass) {
|
|
11
|
+
return class ProgressPlugin extends BaseClass {
|
|
12
|
+
logger;
|
|
13
|
+
state = {};
|
|
14
|
+
constructor({ logger }) {
|
|
15
|
+
super();
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
}
|
|
18
|
+
handler = (percent, message, ...details) => {
|
|
19
|
+
const progress = Math.floor(percent * 100);
|
|
20
|
+
this.logger.status(`${this.logger.colors.green(`${progress}%`)} - ${this.logger.colors.yellow(message)}${details.length > 0 ? `: ${this.logger.colors.dim(...details)}` : ''}`);
|
|
21
|
+
};
|
|
22
|
+
apply(compiler) {
|
|
23
|
+
super.apply(compiler);
|
|
24
|
+
hook(compiler, 'compile', () => {
|
|
25
|
+
this.logger.message('Start compilation');
|
|
26
|
+
if ('rspackVersion' in compiler.webpack) {
|
|
27
|
+
this.logger.message(`Rspack v${compiler.webpack.rspackVersion}`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.logger.message(`Webpack v${compiler.webpack.version}`);
|
|
31
|
+
}
|
|
32
|
+
this.state.start = process.hrtime.bigint();
|
|
33
|
+
});
|
|
34
|
+
hook(compiler, 'invalid', (fileName, changeTime) => {
|
|
35
|
+
this.logger.verbose(`Invalidate file: ${fileName} at ${changeTime}`);
|
|
36
|
+
});
|
|
37
|
+
hook(compiler, 'done', (stats) => {
|
|
38
|
+
const time = this.state.start ? ' in ' + (0, pretty_time_1.elapsedTime)(this.state.start) : '';
|
|
39
|
+
const hasErrors = stats.hasErrors();
|
|
40
|
+
if (hasErrors) {
|
|
41
|
+
this.logger.error('Compiled with some errors' + time);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.logger.success('Compiled successfully' + time);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
19
48
|
};
|
|
20
|
-
apply(compiler) {
|
|
21
|
-
super.apply(compiler);
|
|
22
|
-
hook(compiler, 'compile', () => {
|
|
23
|
-
this._logger.message('Start compilation');
|
|
24
|
-
if ('rspackVersion' in compiler.webpack) {
|
|
25
|
-
this._logger.message(`Rspack v${compiler.webpack.rspackVersion}`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
this._logger.message(`Webpack v${compiler.webpack.version}`);
|
|
29
|
-
}
|
|
30
|
-
this._state.start = process.hrtime.bigint();
|
|
31
|
-
});
|
|
32
|
-
hook(compiler, 'invalid', (fileName, changeTime) => {
|
|
33
|
-
this._logger.verbose(`Invalidate file: ${fileName} at ${changeTime}`);
|
|
34
|
-
});
|
|
35
|
-
hook(compiler, 'done', (stats) => {
|
|
36
|
-
const time = this._state.start ? ' in ' + (0, pretty_time_1.elapsedTime)(this._state.start) : '';
|
|
37
|
-
const hasErrors = stats.hasErrors();
|
|
38
|
-
if (hasErrors) {
|
|
39
|
-
this._logger.error('Compiled with some errors' + time);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
this._logger.success('Compiled successfully' + time);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
49
|
}
|
|
47
|
-
exports.ProgressPlugin = ProgressPlugin;
|
|
48
50
|
function hook(compiler, hookName, callback) {
|
|
49
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
52
|
compiler.hooks[hookName].tap(`app-builder: ${hookName}`, callback);
|
|
51
53
|
}
|
|
54
|
+
exports.WebpackProgressPlugin = createProgressPlugin(webpack_1.default.ProgressPlugin);
|
|
55
|
+
exports.RspackProgressPlugin = createProgressPlugin(core_1.rspack.ProgressPlugin);
|
|
@@ -1,18 +1,7 @@
|
|
|
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';
|
|
4
3
|
import type { Configuration, RuleSetRule as RspackRuleSetRule } from '@rspack/core';
|
|
5
4
|
import type { Logger } from '../logger';
|
|
6
5
|
export declare function clearCacheDirectory(config: Configuration, logger: Logger): void;
|
|
7
6
|
export declare const generateAssetsManifest: ManifestPluginOptions['generate'];
|
|
8
7
|
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,9 @@ 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.
|
|
29
|
+
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");
|
|
34
32
|
const fs = __importStar(require("node:fs"));
|
|
35
33
|
const path = __importStar(require("node:path"));
|
|
36
34
|
const paths_1 = __importDefault(require("../../common/paths"));
|
|
@@ -66,7 +64,7 @@ const generateAssetsManifest = (seed, files, entries) => {
|
|
|
66
64
|
};
|
|
67
65
|
}, {});
|
|
68
66
|
return {
|
|
69
|
-
|
|
67
|
+
...manifestFiles,
|
|
70
68
|
entrypoints,
|
|
71
69
|
};
|
|
72
70
|
};
|
|
@@ -111,80 +109,3 @@ function prepareRspackRules(webpackRules) {
|
|
|
111
109
|
}
|
|
112
110
|
return rspackRules;
|
|
113
111
|
}
|
|
114
|
-
const pretty_time_1 = require("../logger/pretty-time");
|
|
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
|
-
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as Webpack from 'webpack';
|
|
2
2
|
import type { Logger } from '../logger';
|
|
3
|
-
|
|
3
|
+
import { MultiStats } from '@rspack/core';
|
|
4
|
+
export declare function compilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error | null, stats?: Webpack.MultiStats | MultiStats) => Promise<void>;
|
|
4
5
|
export declare function resolveTsConfigPathsToAlias(projectPath: string, filename?: string): {
|
|
5
6
|
aliases?: undefined;
|
|
6
7
|
modules?: undefined;
|
|
@@ -23,13 +23,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.compilerHandlerFactory = compilerHandlerFactory;
|
|
27
27
|
exports.resolveTsConfigPathsToAlias = resolveTsConfigPathsToAlias;
|
|
28
28
|
const path = __importStar(require("node:path"));
|
|
29
29
|
const ts = __importStar(require("typescript"));
|
|
30
30
|
const pretty_time_1 = require("../logger/pretty-time");
|
|
31
31
|
const utils_1 = require("../typescript/utils");
|
|
32
|
-
function
|
|
32
|
+
function compilerHandlerFactory(logger, onCompilationEnd) {
|
|
33
33
|
return async (err, stats) => {
|
|
34
34
|
if (err) {
|
|
35
35
|
logger.panic(err.message, err);
|
package/package.json
CHANGED