@gravity-ui/app-builder 0.33.4-beta.10 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/common/models/index.d.ts +15 -0
- package/dist/common/webpack/config.d.ts +2 -1
- package/dist/common/webpack/config.js +22 -15
- package/dist/common/webpack/storybook.js +2 -0
- package/dist/common/webpack/utils.d.ts +2 -0
- package/dist/common/webpack/utils.js +11 -0
- package/dist/create-cli.d.ts +2 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -304,9 +304,9 @@ self.onmessage = async (ev) => {
|
|
|
304
304
|
```
|
|
305
305
|
|
|
306
306
|
`app-builder` provides built-in support for web workers for files with the `.worker.[jt]s` suffix. You can choose
|
|
307
|
-
between two variants of getting web workers by setting the `
|
|
307
|
+
between two variants of getting web workers by setting the `webWorkerHandle` option:
|
|
308
308
|
|
|
309
|
-
- `
|
|
309
|
+
- `loader` (default) - use the `worker-loader` to import web workers.
|
|
310
310
|
Content of worker file will be included in main bundle as blob. This variant does not
|
|
311
311
|
support dynamic imports inside worker. For example:
|
|
312
312
|
|
|
@@ -328,7 +328,7 @@ declare module '*.worker.ts' {
|
|
|
328
328
|
}
|
|
329
329
|
```
|
|
330
330
|
|
|
331
|
-
- `
|
|
331
|
+
- `cdn-compat` - use the webpack 5 web workers [syntax](https://webpack.js.org/guides/web-workers/#syntax)
|
|
332
332
|
to import web workers. This variant allows to use dynamic imports inside worker and load worker bundle from CDN. For example:
|
|
333
333
|
|
|
334
334
|
```ts
|
|
@@ -337,6 +337,8 @@ import {Worker} from '@gravity-ui/app-builder/worker';
|
|
|
337
337
|
const MyWorker = new Worker(new URL('./my.worker', import.meta.url));
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
+
- `none` - disable worker-specific handling.
|
|
341
|
+
|
|
340
342
|
To use the web worker in your main script, you need to communicate with it using the postMessage and onmessage methods. For example:
|
|
341
343
|
|
|
342
344
|
```ts
|
|
@@ -124,6 +124,7 @@ export type ModuleFederationConfig = Omit<moduleFederationPlugin.ModuleFederatio
|
|
|
124
124
|
prefixSelector: (prefix: string, selector: string, prefixedSelector: string, filePath: string) => string;
|
|
125
125
|
};
|
|
126
126
|
};
|
|
127
|
+
export type WebWorkerHandle = 'loader' | 'cdn-compat' | 'none';
|
|
127
128
|
export interface ClientConfig {
|
|
128
129
|
modules?: string[];
|
|
129
130
|
/**
|
|
@@ -261,8 +262,22 @@ export interface ClientConfig {
|
|
|
261
262
|
cdn?: CdnUploadConfig | CdnUploadConfig[];
|
|
262
263
|
/**
|
|
263
264
|
* use webpack 5 Web Workers [syntax](https://webpack.js.org/guides/web-workers/#syntax)
|
|
265
|
+
*
|
|
266
|
+
* @deprecated use `webWorkerHandle` instead
|
|
264
267
|
*/
|
|
265
268
|
newWebWorkerSyntax?: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* How workers are handled
|
|
271
|
+
* Worker entry point should have `.worker.ts` postfix
|
|
272
|
+
*
|
|
273
|
+
* Files, that match this pattern would be handle with one of the strategies:
|
|
274
|
+
* - 'loader' - `worker-rspack-loader` would be used
|
|
275
|
+
* - 'cdn-compat' - bundler will handle WebWorker syntax, but we also rebuild this worker, to correctly handle publicPath from variable for imports inside worker
|
|
276
|
+
*
|
|
277
|
+
* @see https://www.npmjs.com/package/worker-rspack-loader
|
|
278
|
+
* @see https://webpack.js.org/guides/web-workers/
|
|
279
|
+
*/
|
|
280
|
+
webWorkerHandle?: WebWorkerHandle;
|
|
266
281
|
babelCacheDirectory?: boolean | string;
|
|
267
282
|
cache?: boolean | FileCacheOptions | MemoryCacheOptions;
|
|
268
283
|
/** Use [Lighting CSS](https://lightningcss.dev) to transform and minimize css instead of PostCSS and cssnano*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as webpack from 'webpack';
|
|
2
2
|
import type * as Rspack from '@rspack/core';
|
|
3
|
-
import type { NormalizedClientConfig } from '../models';
|
|
3
|
+
import type { NormalizedClientConfig, WebWorkerHandle } from '../models';
|
|
4
4
|
import type { Logger } from '../logger';
|
|
5
5
|
export interface HelperOptions {
|
|
6
6
|
config: NormalizedClientConfig;
|
|
@@ -12,6 +12,7 @@ export interface HelperOptions {
|
|
|
12
12
|
entriesDirectory: string;
|
|
13
13
|
isSsr: boolean;
|
|
14
14
|
configPath?: string;
|
|
15
|
+
webWorkerHandle: WebWorkerHandle;
|
|
15
16
|
}
|
|
16
17
|
export declare const enum WebpackMode {
|
|
17
18
|
Prod = "production",
|
|
@@ -76,6 +76,7 @@ function getHelperOptions({ webpackMode, config, logger, isSsr = false, configPa
|
|
|
76
76
|
entriesDirectory: isSsr ? paths_1.default.appSsrEntry : paths_1.default.appEntry,
|
|
77
77
|
isSsr,
|
|
78
78
|
configPath,
|
|
79
|
+
webWorkerHandle: (0, utils_1.getNormalizedWorkerOption)(config),
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
82
|
function configureExternals({ config, isSsr }) {
|
|
@@ -586,24 +587,30 @@ function createSourceMapRules(shouldUseSourceMap) {
|
|
|
586
587
|
return [];
|
|
587
588
|
}
|
|
588
589
|
async function createWorkerRule(options) {
|
|
590
|
+
const ruleset = [];
|
|
591
|
+
switch (options.webWorkerHandle) {
|
|
592
|
+
case 'loader':
|
|
593
|
+
ruleset.push({
|
|
594
|
+
loader: require.resolve('worker-rspack-loader'),
|
|
595
|
+
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
596
|
+
// service instead
|
|
597
|
+
options: {
|
|
598
|
+
inline: 'no-fallback',
|
|
599
|
+
},
|
|
600
|
+
});
|
|
601
|
+
break;
|
|
602
|
+
case 'cdn-compat':
|
|
603
|
+
ruleset.push({
|
|
604
|
+
loader: require.resolve('./worker/worker-loader'),
|
|
605
|
+
});
|
|
606
|
+
break;
|
|
607
|
+
case 'none':
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
589
610
|
return {
|
|
590
611
|
test: /\.worker\.[jt]sx?$/,
|
|
591
612
|
exclude: /node_modules/,
|
|
592
|
-
use: [
|
|
593
|
-
options.config.newWebWorkerSyntax
|
|
594
|
-
? {
|
|
595
|
-
loader: require.resolve('./worker/worker-loader'),
|
|
596
|
-
}
|
|
597
|
-
: {
|
|
598
|
-
loader: require.resolve('worker-rspack-loader'),
|
|
599
|
-
// currently workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
600
|
-
// service instead
|
|
601
|
-
options: {
|
|
602
|
-
inline: 'no-fallback',
|
|
603
|
-
},
|
|
604
|
-
},
|
|
605
|
-
await createJavaScriptLoader(options),
|
|
606
|
-
],
|
|
613
|
+
use: [...ruleset, await createJavaScriptLoader(options)],
|
|
607
614
|
};
|
|
608
615
|
}
|
|
609
616
|
function createSassStylesRule(options) {
|
|
@@ -36,6 +36,7 @@ const config_1 = require("./config");
|
|
|
36
36
|
const config_2 = require("../config");
|
|
37
37
|
const models_1 = require("../models");
|
|
38
38
|
const paths_1 = __importDefault(require("../paths"));
|
|
39
|
+
const utils_1 = require("./utils");
|
|
39
40
|
async function configureServiceWebpackConfig(mode, storybookConfig) {
|
|
40
41
|
const serviceConfig = await (0, config_2.getProjectConfig)(mode === "production" /* WebpackMode.Prod */ ? 'build' : 'dev', {
|
|
41
42
|
storybook: true,
|
|
@@ -115,6 +116,7 @@ async function configureWebpackConfigForStorybook(mode, userConfig = {}, storybo
|
|
|
115
116
|
buildDirectory: config.client.outputPath || paths_1.default.appBuild,
|
|
116
117
|
entriesDirectory: paths_1.default.appEntry,
|
|
117
118
|
isSsr: false,
|
|
119
|
+
webWorkerHandle: (0, utils_1.getNormalizedWorkerOption)(config.client),
|
|
118
120
|
};
|
|
119
121
|
return {
|
|
120
122
|
module: {
|
|
@@ -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
|
+
import { NormalizedClientConfig, WebWorkerHandle } from '../models';
|
|
4
5
|
export declare function compilerHandlerFactory(logger: Logger, onCompilationEnd?: () => void): (err?: Error | null, stats?: Webpack.MultiStats | MultiStats) => Promise<void>;
|
|
5
6
|
export declare function resolveTsConfigPathsToAlias(projectPath: string, filename?: string): {
|
|
6
7
|
aliases?: undefined;
|
|
@@ -9,3 +10,4 @@ export declare function resolveTsConfigPathsToAlias(projectPath: string, filenam
|
|
|
9
10
|
aliases: Record<string, string[]>;
|
|
10
11
|
modules: string[];
|
|
11
12
|
};
|
|
13
|
+
export declare function getNormalizedWorkerOption(config: NormalizedClientConfig): WebWorkerHandle;
|
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.compilerHandlerFactory = compilerHandlerFactory;
|
|
27
27
|
exports.resolveTsConfigPathsToAlias = resolveTsConfigPathsToAlias;
|
|
28
|
+
exports.getNormalizedWorkerOption = getNormalizedWorkerOption;
|
|
28
29
|
const path = __importStar(require("node:path"));
|
|
29
30
|
const ts = __importStar(require("typescript"));
|
|
30
31
|
const pretty_time_1 = require("../logger/pretty-time");
|
|
@@ -99,3 +100,13 @@ function resolveTsConfigPathsToAlias(projectPath, filename = 'tsconfig.json') {
|
|
|
99
100
|
}
|
|
100
101
|
return { aliases, modules };
|
|
101
102
|
}
|
|
103
|
+
function getNormalizedWorkerOption(config) {
|
|
104
|
+
let webWorkerHandle = 'loader';
|
|
105
|
+
if (config.newWebWorkerSyntax) {
|
|
106
|
+
webWorkerHandle = 'cdn-compat';
|
|
107
|
+
}
|
|
108
|
+
if (config.webWorkerHandle) {
|
|
109
|
+
webWorkerHandle = config.webWorkerHandle;
|
|
110
|
+
}
|
|
111
|
+
return webWorkerHandle;
|
|
112
|
+
}
|
package/dist/create-cli.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export type CliArgs = Awaited<ReturnType<typeof createCli>>;
|
|
|
2
2
|
export declare function createCli(argv: string[]): {
|
|
3
3
|
[x: string]: unknown;
|
|
4
4
|
verbose: boolean | undefined;
|
|
5
|
-
env: string[] | undefined;
|
|
6
5
|
cdn: string | undefined;
|
|
6
|
+
env: string[] | undefined;
|
|
7
7
|
target: "client" | "server" | undefined;
|
|
8
8
|
c: unknown;
|
|
9
9
|
inspect: number | undefined;
|
|
@@ -32,8 +32,8 @@ export declare function createCli(argv: string[]): {
|
|
|
32
32
|
} | Promise<{
|
|
33
33
|
[x: string]: unknown;
|
|
34
34
|
verbose: boolean | undefined;
|
|
35
|
-
env: string[] | undefined;
|
|
36
35
|
cdn: string | undefined;
|
|
36
|
+
env: string[] | undefined;
|
|
37
37
|
target: "client" | "server" | undefined;
|
|
38
38
|
c: unknown;
|
|
39
39
|
inspect: number | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/app-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Develop and build your React client-server projects, powered by typescript and webpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
|
|
74
74
|
"@rsdoctor/rspack-plugin": "^1.0.2",
|
|
75
75
|
"@rsdoctor/webpack-plugin": "^1.0.2",
|
|
76
|
-
"@rspack/core": "1.
|
|
76
|
+
"@rspack/core": "1.5.5",
|
|
77
77
|
"@rspack/dev-server": "^1.1.4",
|
|
78
|
-
"@rspack/plugin-react-refresh": "^1.5.
|
|
78
|
+
"@rspack/plugin-react-refresh": "^1.5.1",
|
|
79
79
|
"@statoscope/stats": "^5.28.1",
|
|
80
80
|
"@statoscope/stats-extension-compressed": "^5.28.1",
|
|
81
81
|
"@statoscope/webpack-model": "^5.29.0",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"@svgr/plugin-jsx": "^8.1.0",
|
|
85
85
|
"@svgr/webpack": "^8.1.0",
|
|
86
86
|
"@swc/cli": "0.7.8",
|
|
87
|
-
"@swc/core": "1.
|
|
88
|
-
"@swc/plugin-transform-imports": "
|
|
87
|
+
"@swc/core": "1.13.5",
|
|
88
|
+
"@swc/plugin-transform-imports": "9.1.0",
|
|
89
89
|
"babel-loader": "^9.2.1",
|
|
90
90
|
"babel-plugin-import": "^1.13.8",
|
|
91
91
|
"babel-plugin-inline-react-svg": "^2.0.2",
|