@gravity-ui/app-builder 0.33.4-beta.10 → 0.34.1-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/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 `newWebWorkerSyntax` option:
307
+ between two variants of getting web workers by setting the `webWorkerHandle` option:
308
308
 
309
- - `newWebWorkerSyntax: false` (default) - use the `worker-loader` to import web workers.
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
- - `newWebWorkerSyntax: true` - use the webpack 5 web workers [syntax](https://webpack.js.org/guides/web-workers/#syntax)
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
@@ -3,7 +3,7 @@ import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
3
3
  import type { IFeatureDefinition } from 'monaco-editor-webpack-plugin/out/types';
4
4
  import type { Options as MomentTzOptions } from 'moment-timezone-data-webpack-plugin';
5
5
  import type { Configuration, DefinePlugin, FileCacheOptions, MemoryCacheOptions } from 'webpack';
6
- import type { LightningCssMinimizerRspackPluginOptions, Configuration as RspackConfiguration, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
6
+ import type { LazyCompilationOptions, LightningCssMinimizerRspackPluginOptions, Configuration as RspackConfiguration, SwcJsMinimizerRspackPluginOptions } from '@rspack/core';
7
7
  import type * as Babel from '@babel/core';
8
8
  import type * as Swc from '@swc/core';
9
9
  import type { ServerConfiguration } from 'webpack-dev-server';
@@ -52,13 +52,8 @@ export interface LibraryConfig {
52
52
  };
53
53
  verbose?: boolean;
54
54
  }
55
- interface LazyCompilationConfig {
55
+ interface LazyCompilationConfig extends Pick<LazyCompilationOptions, 'imports' | 'entries' | 'test'> {
56
56
  port?: number;
57
- /**
58
- * @default true
59
- * disable lazy compilation for entries
60
- */
61
- entries?: boolean;
62
57
  }
63
58
  export type ModuleFederationConfig = Omit<moduleFederationPlugin.ModuleFederationPluginOptions, 'name' | 'remotes'> & {
64
59
  /**
@@ -124,6 +119,7 @@ export type ModuleFederationConfig = Omit<moduleFederationPlugin.ModuleFederatio
124
119
  prefixSelector: (prefix: string, selector: string, prefixedSelector: string, filePath: string) => string;
125
120
  };
126
121
  };
122
+ export type WebWorkerHandle = 'loader' | 'cdn-compat' | 'none';
127
123
  export interface ClientConfig {
128
124
  modules?: string[];
129
125
  /**
@@ -261,8 +257,22 @@ export interface ClientConfig {
261
257
  cdn?: CdnUploadConfig | CdnUploadConfig[];
262
258
  /**
263
259
  * use webpack 5 Web Workers [syntax](https://webpack.js.org/guides/web-workers/#syntax)
260
+ *
261
+ * @deprecated use `webWorkerHandle` instead
264
262
  */
265
263
  newWebWorkerSyntax?: boolean;
264
+ /**
265
+ * How workers are handled
266
+ * Worker entry point should have `.worker.ts` postfix
267
+ *
268
+ * Files, that match this pattern would be handle with one of the strategies:
269
+ * - 'loader' - `worker-rspack-loader` would be used
270
+ * - 'cdn-compat' - bundler will handle WebWorker syntax, but we also rebuild this worker, to correctly handle publicPath from variable for imports inside worker
271
+ *
272
+ * @see https://www.npmjs.com/package/worker-rspack-loader
273
+ * @see https://webpack.js.org/guides/web-workers/
274
+ */
275
+ webWorkerHandle?: WebWorkerHandle;
266
276
  babelCacheDirectory?: boolean | string;
267
277
  cache?: boolean | FileCacheOptions | MemoryCacheOptions;
268
278
  /** 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 }) {
@@ -309,6 +310,7 @@ function configureRspackExperiments(options) {
309
310
  entries: false,
310
311
  imports: true,
311
312
  prefix: '/build/lazy-',
313
+ test: config.lazyCompilation?.test ?? undefined,
312
314
  };
313
315
  }
314
316
  const filesystemCacheOptions = typeof config.cache === 'object' && config.cache.type === 'filesystem'
@@ -586,24 +588,30 @@ function createSourceMapRules(shouldUseSourceMap) {
586
588
  return [];
587
589
  }
588
590
  async function createWorkerRule(options) {
591
+ const ruleset = [];
592
+ switch (options.webWorkerHandle) {
593
+ case 'loader':
594
+ ruleset.push({
595
+ loader: require.resolve('worker-rspack-loader'),
596
+ // currently workers located on cdn are not working properly, so we are enforcing loading workers from
597
+ // service instead
598
+ options: {
599
+ inline: 'no-fallback',
600
+ },
601
+ });
602
+ break;
603
+ case 'cdn-compat':
604
+ ruleset.push({
605
+ loader: require.resolve('./worker/worker-loader'),
606
+ });
607
+ break;
608
+ case 'none':
609
+ break;
610
+ }
589
611
  return {
590
612
  test: /\.worker\.[jt]sx?$/,
591
613
  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
- ],
614
+ use: [...ruleset, await createJavaScriptLoader(options)],
607
615
  };
608
616
  }
609
617
  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
+ }
@@ -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.33.4-beta.10",
3
+ "version": "0.34.1-beta.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.6.5",
76
+ "@rspack/core": "1.5.5",
77
77
  "@rspack/dev-server": "^1.1.4",
78
- "@rspack/plugin-react-refresh": "^1.5.3",
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.14.0",
88
- "@swc/plugin-transform-imports": "10.0.0",
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",