@gravity-ui/app-builder 0.14.0-beta.0 → 0.14.0-beta.1
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
|
@@ -192,8 +192,11 @@ With this `{rootDir}/src/ui/tsconfig.json`:
|
|
|
192
192
|
- `forkTsCheker` (`false | ForkTsCheckerWebpackPluginOptions`) - config for ForkTsCheckerWebpackPlugin [more](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#options). If `false`, ForkTsCheckerWebpackPlugin will be disabled.
|
|
193
193
|
- `cache` (`boolean | FileCacheOptions | MemoryCacheOptions`) — Cache the generated webpack modules and chunks to improve build speed. [more](https://webpack.js.org/configuration/cache/)
|
|
194
194
|
- `babelCacheDirectory` (`boolean | string`) — Set directory for babel-loader cache (`default: node_modules/.cache/babel-loader``)
|
|
195
|
-
- `babel` (`(config: babel.TransformOptions, options: {configType: 'development' | 'production'}) => babel.TransformOptions | Promise<babel.TransformOptions>`) - Allow override the default babel transform options.
|
|
196
|
-
- `webpack` (`(config: webpack.Configuration, options: {configType: 'development' | 'production'}) => webpack.Configuration | Promise<webpack.Configuration>`) - Allow override the default configuration.
|
|
195
|
+
- `babel` (`(config: babel.TransformOptions, options: {configType: 'development' | 'production'; isSsr: boolean}) => babel.TransformOptions | Promise<babel.TransformOptions>`) - Allow override the default babel transform options.
|
|
196
|
+
- `webpack` (`(config: webpack.Configuration, options: {configType: 'development' | 'production'; isSsr: boolean}) => webpack.Configuration | Promise<webpack.Configuration>`) - Allow override the default configuration.
|
|
197
|
+
- `ssr` - build SSR bundle. The SSR entries should be inside `src/ui/ssr` directory and match the client entries.
|
|
198
|
+
- `noExternal` (`string | RegExp | (string | RegExp)[] | true`) - prevent listed dependencies from being externalized for SSR. By default, all dependencies are externalized.
|
|
199
|
+
- `moduleType`: (`'commonjs' | 'esm'`) - library type for the SSR bundle, by default `commonjs`.
|
|
197
200
|
|
|
198
201
|
##### Dev build
|
|
199
202
|
|
|
@@ -5,7 +5,11 @@ function babelPreset(config) {
|
|
|
5
5
|
return [
|
|
6
6
|
require.resolve('./ui-preset'),
|
|
7
7
|
{
|
|
8
|
-
env: {
|
|
8
|
+
env: {
|
|
9
|
+
modules: false,
|
|
10
|
+
bugfixes: true,
|
|
11
|
+
targets: config.isSsr ? { node: 'current' } : undefined,
|
|
12
|
+
},
|
|
9
13
|
runtime: { version: '^7.13.10' },
|
|
10
14
|
typescript: true,
|
|
11
15
|
react: {
|
|
@@ -180,12 +180,14 @@ export interface ClientConfig {
|
|
|
180
180
|
*/
|
|
181
181
|
webpack?: (config: Configuration, options: {
|
|
182
182
|
configType: `${WebpackMode}`;
|
|
183
|
+
isSsr?: boolean;
|
|
183
184
|
}) => Configuration | Promise<Configuration>;
|
|
184
185
|
/**
|
|
185
186
|
* Modify or return a custom Babel config.
|
|
186
187
|
*/
|
|
187
188
|
babel?: (config: Babel.TransformOptions, options: {
|
|
188
189
|
configType: `${WebpackMode}`;
|
|
190
|
+
isSsr: boolean;
|
|
189
191
|
}) => Babel.TransformOptions | Promise<Babel.TransformOptions>;
|
|
190
192
|
/**
|
|
191
193
|
* Modify or return a custom [Terser options](https://github.com/terser/terser#minify-options).
|
|
@@ -234,10 +236,12 @@ export type NormalizedClientConfig = Omit<ClientConfig, 'publicPathPrefix' | 'hi
|
|
|
234
236
|
verbose?: boolean;
|
|
235
237
|
webpack: (config: Configuration, options: {
|
|
236
238
|
configType: `${WebpackMode}`;
|
|
239
|
+
isSsr: boolean;
|
|
237
240
|
}) => Configuration | Promise<Configuration>;
|
|
238
241
|
debugWebpack?: boolean;
|
|
239
242
|
babel: (config: Babel.TransformOptions, options: {
|
|
240
243
|
configType: `${WebpackMode}`;
|
|
244
|
+
isSsr: boolean;
|
|
241
245
|
}) => Babel.TransformOptions | Promise<Babel.TransformOptions>;
|
|
242
246
|
reactRefresh: NonNullable<ClientConfig['reactRefresh']>;
|
|
243
247
|
};
|
|
@@ -107,7 +107,7 @@ async function webpackConfigFactory(webpackMode, config, { logger, isSsr = false
|
|
|
107
107
|
},
|
|
108
108
|
cache: config.cache,
|
|
109
109
|
};
|
|
110
|
-
webpackConfig = await config.webpack(webpackConfig, { configType: webpackMode });
|
|
110
|
+
webpackConfig = await config.webpack(webpackConfig, { configType: webpackMode, isSsr });
|
|
111
111
|
if (config.debugWebpack) {
|
|
112
112
|
(0, log_config_1.logConfig)('Preview webpack config', webpackConfig);
|
|
113
113
|
}
|
|
@@ -273,9 +273,9 @@ function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType,
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
const transformOptions = config.babel({
|
|
276
|
-
presets: [(0, babel_1.babelPreset)(config)],
|
|
276
|
+
presets: [(0, babel_1.babelPreset)({ newJsxTransform: config.newJsxTransform, isSsr })],
|
|
277
277
|
plugins,
|
|
278
|
-
}, { configType });
|
|
278
|
+
}, { configType, isSsr });
|
|
279
279
|
return {
|
|
280
280
|
loader: require.resolve('babel-loader'),
|
|
281
281
|
options: {
|
|
@@ -407,8 +407,8 @@ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, add
|
|
|
407
407
|
loaders.unshift({ loader: mini_css_extract_plugin_1.default.loader, options: { emit: !isSsr } });
|
|
408
408
|
}
|
|
409
409
|
if (isEnvDevelopment) {
|
|
410
|
-
if (isSsr) {
|
|
411
|
-
loaders.unshift({ loader: mini_css_extract_plugin_1.default.loader, options: { emit:
|
|
410
|
+
if (isSsr || config.ssr) {
|
|
411
|
+
loaders.unshift({ loader: mini_css_extract_plugin_1.default.loader, options: { emit: !isSsr } });
|
|
412
412
|
}
|
|
413
413
|
else {
|
|
414
414
|
loaders.unshift({
|
|
@@ -455,7 +455,7 @@ function createIconsRule({ isEnvProduction, config, isSsr }, jsLoader) {
|
|
|
455
455
|
generator: {
|
|
456
456
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
457
457
|
publicPath: isEnvProduction ? '../' : undefined,
|
|
458
|
-
emit:
|
|
458
|
+
emit: isSsr ? false : undefined,
|
|
459
459
|
},
|
|
460
460
|
}),
|
|
461
461
|
};
|
|
@@ -472,7 +472,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
472
472
|
},
|
|
473
473
|
generator: {
|
|
474
474
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
475
|
-
emit:
|
|
475
|
+
emit: isSsr ? false : undefined,
|
|
476
476
|
},
|
|
477
477
|
};
|
|
478
478
|
const fontsRule = {
|
|
@@ -486,7 +486,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
486
486
|
},
|
|
487
487
|
generator: {
|
|
488
488
|
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
489
|
-
emit:
|
|
489
|
+
emit: isSsr ? false : undefined,
|
|
490
490
|
},
|
|
491
491
|
};
|
|
492
492
|
const rules = [imagesRule, fontsRule];
|
|
@@ -506,7 +506,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
506
506
|
generator: {
|
|
507
507
|
filename: 'assets/images/[name].[contenthash:8][ext]',
|
|
508
508
|
publicPath: '../',
|
|
509
|
-
emit:
|
|
509
|
+
emit: isSsr ? false : undefined,
|
|
510
510
|
},
|
|
511
511
|
}, {
|
|
512
512
|
test: /\.(ttf|eot|woff2?)$/,
|
|
@@ -521,7 +521,7 @@ function createAssetsRules({ isEnvProduction, config, isSsr }) {
|
|
|
521
521
|
generator: {
|
|
522
522
|
filename: 'assets/fonts/[name].[contenthash:8][ext]',
|
|
523
523
|
publicPath: '../',
|
|
524
|
-
emit:
|
|
524
|
+
emit: isSsr ? false : undefined,
|
|
525
525
|
},
|
|
526
526
|
});
|
|
527
527
|
}
|
|
@@ -533,7 +533,7 @@ function createFallbackRules({ isEnvProduction, isSsr }) {
|
|
|
533
533
|
type: 'asset/resource',
|
|
534
534
|
generator: {
|
|
535
535
|
filename: 'assets/[name].[contenthash:8][ext]',
|
|
536
|
-
emit:
|
|
536
|
+
emit: isSsr ? false : undefined,
|
|
537
537
|
},
|
|
538
538
|
exclude: [/\.[jt]sx?$/, /\.json$/, /\.[cm]js$/, /\.ejs$/],
|
|
539
539
|
},
|
|
@@ -548,7 +548,7 @@ function createFallbackRules({ isEnvProduction, isSsr }) {
|
|
|
548
548
|
generator: {
|
|
549
549
|
filename: 'assets/[name].[contenthash:8][ext]',
|
|
550
550
|
publicPath: '../',
|
|
551
|
-
emit:
|
|
551
|
+
emit: isSsr ? false : undefined,
|
|
552
552
|
},
|
|
553
553
|
});
|
|
554
554
|
}
|
|
@@ -591,6 +591,7 @@ function configurePlugins(options) {
|
|
|
591
591
|
}),
|
|
592
592
|
new webpack.DefinePlugin({
|
|
593
593
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
594
|
+
'process.env.IS_SSR': JSON.stringify(isSsr),
|
|
594
595
|
...config.definitions,
|
|
595
596
|
}),
|
|
596
597
|
];
|
|
@@ -645,24 +646,26 @@ function configurePlugins(options) {
|
|
|
645
646
|
}));
|
|
646
647
|
}
|
|
647
648
|
}
|
|
648
|
-
if (isEnvProduction || isSsr) {
|
|
649
|
+
if (isEnvProduction || isSsr || config.ssr) {
|
|
649
650
|
plugins.push(new mini_css_extract_plugin_1.default({
|
|
650
|
-
filename: 'css/[name].[contenthash:8].css',
|
|
651
|
-
chunkFilename:
|
|
651
|
+
filename: isEnvProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css',
|
|
652
|
+
chunkFilename: isEnvProduction
|
|
653
|
+
? 'css/[name].[contenthash:8].chunk.css'
|
|
654
|
+
: 'css/[name].chunk.css',
|
|
652
655
|
ignoreOrder: true,
|
|
653
656
|
}));
|
|
654
657
|
}
|
|
655
|
-
if (config.monaco) {
|
|
656
|
-
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
657
|
-
plugins.push(new MonacoEditorWebpackPlugin({
|
|
658
|
-
filename: isEnvProduction ? '[name].[hash:8].worker.js' : undefined,
|
|
659
|
-
...config.monaco,
|
|
660
|
-
// currently, workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
661
|
-
// service instead
|
|
662
|
-
publicPath: path.normalize(config.publicPathPrefix + '/build/'),
|
|
663
|
-
}));
|
|
664
|
-
}
|
|
665
658
|
if (!isSsr) {
|
|
659
|
+
if (config.monaco) {
|
|
660
|
+
const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
|
|
661
|
+
plugins.push(new MonacoEditorWebpackPlugin({
|
|
662
|
+
filename: isEnvProduction ? '[name].[hash:8].worker.js' : undefined,
|
|
663
|
+
...config.monaco,
|
|
664
|
+
// currently, workers located on cdn are not working properly, so we are enforcing loading workers from
|
|
665
|
+
// service instead
|
|
666
|
+
publicPath: path.normalize(config.publicPathPrefix + '/build/'),
|
|
667
|
+
}));
|
|
668
|
+
}
|
|
666
669
|
const contextReplacement = config.contextReplacement || {};
|
|
667
670
|
plugins.push(createMomentTimezoneDataPlugin(config.momentTz));
|
|
668
671
|
plugins.push(new webpack.ContextReplacementPlugin(/moment[\\/]locale$/,
|
|
@@ -55,15 +55,12 @@ function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
|
|
|
55
55
|
const time = clientStats.endTime - clientStats.startTime;
|
|
56
56
|
logger.success(`Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1_000_000))}`);
|
|
57
57
|
}
|
|
58
|
-
else {
|
|
59
|
-
logger.success(`Client was successfully compiled`);
|
|
60
|
-
}
|
|
61
58
|
if (ssrStats) {
|
|
62
59
|
const time = ssrStats.endTime - ssrStats.startTime;
|
|
63
60
|
logger.success(`SSR: Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1_000_000))}`);
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
logger.success(`
|
|
62
|
+
if (!clientStats && !ssrStats) {
|
|
63
|
+
logger.success(`Client was successfully compiled`);
|
|
67
64
|
}
|
|
68
65
|
};
|
|
69
66
|
}
|
package/package.json
CHANGED