@gravity-ui/app-builder 0.15.1-beta.4 → 0.15.1-beta.6

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.
@@ -207,6 +207,11 @@ export interface ClientConfig {
207
207
  moduleType?: 'commonjs' | 'esm';
208
208
  };
209
209
  bundler?: Bundler;
210
+ /**
211
+ * Code loader. `babel` is default.
212
+ * `swc` is experimental and supported only in `rspack` bundler
213
+ */
214
+ codeLoader?: 'babel' | 'swc';
210
215
  }
211
216
  export interface CdnUploadConfig {
212
217
  bucket: string;
@@ -40,12 +40,12 @@ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checke
40
40
  const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
41
41
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
42
42
  const webpack_assets_manifest_1 = __importDefault(require("webpack-assets-manifest"));
43
+ const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
43
44
  const react_refresh_webpack_plugin_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
44
45
  const moment_timezone_data_webpack_plugin_1 = __importDefault(require("moment-timezone-data-webpack-plugin"));
45
46
  const webpack_plugin_1 = __importDefault(require("@statoscope/webpack-plugin"));
46
47
  const circular_dependency_plugin_1 = __importDefault(require("circular-dependency-plugin"));
47
48
  const core_1 = require("@rspack/core");
48
- const rspack_manifest_plugin_1 = require("rspack-manifest-plugin");
49
49
  const rspack_1 = require("./rspack");
50
50
  const ts_checker_rspack_plugin_1 = require("ts-checker-rspack-plugin");
51
51
  const plugin_react_refresh_1 = __importDefault(require("@rspack/plugin-react-refresh"));
@@ -370,6 +370,61 @@ function configureOutput(options) {
370
370
  };
371
371
  }
372
372
  function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, configType, config, isSsr, }) {
373
+ if (config.codeLoader === 'swc') {
374
+ if (config.bundler !== 'rspack') {
375
+ throw new Error('SWC is supported only with rspack bundler');
376
+ }
377
+ const browserslist = require('browserslist');
378
+ return {
379
+ loader: 'builtin:swc-loader',
380
+ options: {
381
+ sourceMaps: !config.disableSourceMapGeneration,
382
+ env: {
383
+ loose: true,
384
+ bugfixes: true,
385
+ targets: browserslist(),
386
+ },
387
+ module: {
388
+ type: 'es6',
389
+ noInterop: true,
390
+ },
391
+ assumptions: {
392
+ setPublicClassFields: true,
393
+ privateFieldsAsProperties: true,
394
+ },
395
+ jsc: {
396
+ parser: {
397
+ syntax: 'typescript',
398
+ tsx: true,
399
+ decorators: true,
400
+ dynamicImport: true,
401
+ },
402
+ transform: {
403
+ react: {
404
+ runtime: config.newJsxTransform ? 'automatic' : 'classic',
405
+ development: isEnvDevelopment,
406
+ refresh: !isSsr && isEnvDevelopment && config.reactRefresh !== false,
407
+ useBuiltIns: true,
408
+ },
409
+ },
410
+ experimental: {
411
+ plugins: !isSsr && isEnvProduction
412
+ ? [
413
+ [
414
+ '@swc/plugin-transform-imports',
415
+ {
416
+ lodash: {
417
+ transform: 'lodash/{{member}}',
418
+ },
419
+ },
420
+ ],
421
+ ]
422
+ : [],
423
+ },
424
+ },
425
+ },
426
+ };
427
+ }
373
428
  const plugins = [];
374
429
  if (!isSsr) {
375
430
  if (isEnvDevelopment && config.reactRefresh !== false) {
@@ -492,7 +547,7 @@ function createStylesRule(options) {
492
547
  function getCssLoaders({ isEnvDevelopment, isEnvProduction, config, isSsr }, additionalRules) {
493
548
  const isRspack = config.bundler === 'rspack';
494
549
  const loaders = [];
495
- if (!config.transformCssWithLightningCss) {
550
+ if (!config.transformCssWithLightningCss && config.bundler !== 'rspack') {
496
551
  loaders.push({
497
552
  loader: require.resolve('postcss-loader'),
498
553
  options: {
@@ -768,11 +823,24 @@ const commonBundlerPlugins = {
768
823
  rspack: progress_plugin_1.RspackProgressPlugin,
769
824
  webpack: progress_plugin_1.WebpackProgressPlugin,
770
825
  },
826
+ ManifestPlugin: {
827
+ rspack: rspack_manifest_plugin_1.RspackManifestPlugin,
828
+ webpack: webpack_manifest_plugin_1.WebpackManifestPlugin,
829
+ },
830
+ TsCheckerRspackPlugin: {
831
+ rspack: ts_checker_rspack_plugin_1.TsCheckerRspackPlugin,
832
+ webpack: fork_ts_checker_webpack_plugin_1.default,
833
+ },
834
+ CSSExtractPlugin: {
835
+ rspack: core_1.CssExtractRspackPlugin,
836
+ webpack: mini_css_extract_plugin_1.default,
837
+ },
771
838
  };
772
839
  function configureCommonPlugins(options) {
773
840
  const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
774
841
  const excludeFromClean = config.excludeFromClean || [];
775
842
  const bundler = config.bundler;
843
+ const forkTsCheckerOptions = getForkTsCheckerOptions(options);
776
844
  const plugins = [
777
845
  new clean_webpack_plugin_1.CleanWebpackPlugin({
778
846
  verbose: config.verbose,
@@ -782,10 +850,17 @@ function configureCommonPlugins(options) {
782
850
  ...excludeFromClean,
783
851
  ],
784
852
  }),
853
+ new commonBundlerPlugins['ManifestPlugin'][bundler]({
854
+ writeToFileEmit: true,
855
+ publicPath: '',
856
+ }),
785
857
  new commonBundlerPlugins['DefinePlugin'][bundler](getDefinitions(options)),
786
858
  ...(options.logger
787
859
  ? [new commonBundlerPlugins['ProgressPlugin'][bundler]({ logger: options.logger })]
788
860
  : []),
861
+ ...(forkTsCheckerOptions
862
+ ? [new commonBundlerPlugins['TsCheckerRspackPlugin'][bundler](forkTsCheckerOptions)]
863
+ : []),
789
864
  ];
790
865
  if (config.detectCircularDependencies) {
791
866
  let circularPluginOptions = {
@@ -806,6 +881,9 @@ function configureCommonPlugins(options) {
806
881
  }));
807
882
  }
808
883
  }
884
+ if (isEnvProduction || isSsr || config.ssr) {
885
+ plugins.push(new commonBundlerPlugins['CSSExtractPlugin'][bundler](getCssExtractPluginOptions(options)));
886
+ }
809
887
  if (!isSsr) {
810
888
  const contextReplacements = getContextReplacements(options);
811
889
  contextReplacements.forEach(({ resourceRegExp, newResource }) => plugins.push(new commonBundlerPlugins['ContextReplacementPlugin'][bundler](resourceRegExp, newResource)));
@@ -851,13 +929,8 @@ function configureCommonPlugins(options) {
851
929
  }
852
930
  function configureWebpackPlugins(options) {
853
931
  const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
854
- const forkTsCheckerOptions = getForkTsCheckerOptions(options);
855
932
  const webpackPlugins = [
856
933
  ...configureCommonPlugins(options),
857
- new webpack_manifest_plugin_1.WebpackManifestPlugin({
858
- writeToFileEmit: true,
859
- publicPath: '',
860
- }),
861
934
  new webpack_assets_manifest_1.default(isEnvProduction
862
935
  ? {
863
936
  entrypoints: true,
@@ -869,11 +942,7 @@ function configureWebpackPlugins(options) {
869
942
  output: path.resolve(options.buildDirectory, assetsManifestFile),
870
943
  }),
871
944
  ...(process.env.WEBPACK_PROFILE === 'true' ? [new webpack.debug.ProfilingPlugin()] : []),
872
- ...(forkTsCheckerOptions ? [new fork_ts_checker_webpack_plugin_1.default(forkTsCheckerOptions)] : []),
873
945
  ];
874
- if (isEnvProduction || isSsr || config.ssr) {
875
- webpackPlugins.push(new mini_css_extract_plugin_1.default(getCssExtractPluginOptions(options)));
876
- }
877
946
  if (isEnvProduction) {
878
947
  if (config.analyzeBundle === 'rsdoctor') {
879
948
  const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
@@ -894,23 +963,18 @@ function configureWebpackPlugins(options) {
894
963
  }
895
964
  function configureRspackPlugins(options) {
896
965
  const { isEnvDevelopment, isEnvProduction, config, isSsr } = options;
897
- const forkTsCheckerOptions = getForkTsCheckerOptions(options);
898
966
  const rspackPlugins = [
899
967
  ...configureCommonPlugins(options),
900
968
  new rspack_manifest_plugin_1.RspackManifestPlugin({
901
969
  fileName: isEnvProduction
902
970
  ? assetsManifestFile
903
- : path.resolve(paths_1.default.appBuild, assetsManifestFile),
971
+ : path.resolve(options.buildDirectory, assetsManifestFile),
904
972
  writeToFileEmit: true,
905
973
  useLegacyEmit: true,
906
974
  publicPath: '',
907
975
  generate: rspack_1.generateAssetsManifest,
908
976
  }),
909
- ...(forkTsCheckerOptions ? [new ts_checker_rspack_plugin_1.TsCheckerRspackPlugin(forkTsCheckerOptions)] : []),
910
977
  ];
911
- if (isEnvProduction || isSsr || config.ssr) {
912
- rspackPlugins.push(new core_1.CssExtractRspackPlugin(getCssExtractPluginOptions(options)));
913
- }
914
978
  if (isEnvProduction) {
915
979
  if (config.analyzeBundle === 'rsdoctor') {
916
980
  const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.15.1-beta.4",
3
+ "version": "0.15.1-beta.6",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -79,6 +79,7 @@
79
79
  "@svgr/core": "^8.1.0",
80
80
  "@svgr/plugin-jsx": "^8.1.0",
81
81
  "@svgr/webpack": "^8.1.0",
82
+ "@swc/plugin-transform-imports": "^6.1.0",
82
83
  "babel-loader": "^9.2.1",
83
84
  "babel-plugin-import": "^1.13.8",
84
85
  "babel-plugin-inline-react-svg": "^2.0.2",