@rsbuild/core 0.0.0-nightly-20231017024751

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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +24 -0
  3. package/dist/createBuilder.d.ts +2 -0
  4. package/dist/createBuilder.js +51 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +21 -0
  7. package/dist/plugins/antd.d.ts +3 -0
  8. package/dist/plugins/antd.js +56 -0
  9. package/dist/plugins/arco.d.ts +2 -0
  10. package/dist/plugins/arco.js +44 -0
  11. package/dist/plugins/asset.d.ts +2 -0
  12. package/dist/plugins/asset.js +36 -0
  13. package/dist/plugins/assetsRetry.d.ts +2 -0
  14. package/dist/plugins/assetsRetry.js +77 -0
  15. package/dist/plugins/bundleAnalyzer.d.ts +2 -0
  16. package/dist/plugins/bundleAnalyzer.js +72 -0
  17. package/dist/plugins/cache.d.ts +2 -0
  18. package/dist/plugins/cache.js +147 -0
  19. package/dist/plugins/checkSyntax.d.ts +2 -0
  20. package/dist/plugins/checkSyntax.js +86 -0
  21. package/dist/plugins/cleanOutput.d.ts +2 -0
  22. package/dist/plugins/cleanOutput.js +65 -0
  23. package/dist/plugins/define.d.ts +2 -0
  24. package/dist/plugins/define.js +79 -0
  25. package/dist/plugins/devtool.d.ts +2 -0
  26. package/dist/plugins/devtool.js +26 -0
  27. package/dist/plugins/entry.d.ts +2 -0
  28. package/dist/plugins/entry.js +30 -0
  29. package/dist/plugins/externals.d.ts +2 -0
  30. package/dist/plugins/externals.js +31 -0
  31. package/dist/plugins/fileSize.d.ts +4 -0
  32. package/dist/plugins/fileSize.js +188 -0
  33. package/dist/plugins/html.d.ts +3 -0
  34. package/dist/plugins/html.js +261 -0
  35. package/dist/plugins/index.d.ts +2 -0
  36. package/dist/plugins/index.js +83 -0
  37. package/dist/plugins/inlineChunk.d.ts +2 -0
  38. package/dist/plugins/inlineChunk.js +95 -0
  39. package/dist/plugins/moment.d.ts +2 -0
  40. package/dist/plugins/moment.js +26 -0
  41. package/dist/plugins/networkPerformance.d.ts +2 -0
  42. package/dist/plugins/networkPerformance.js +37 -0
  43. package/dist/plugins/nodeAddons.d.ts +2 -0
  44. package/dist/plugins/nodeAddons.js +86 -0
  45. package/dist/plugins/performance.d.ts +5 -0
  46. package/dist/plugins/performance.js +49 -0
  47. package/dist/plugins/preloadOrPrefetch.d.ts +2 -0
  48. package/dist/plugins/preloadOrPrefetch.js +40 -0
  49. package/dist/plugins/rem.d.ts +2 -0
  50. package/dist/plugins/rem.js +124 -0
  51. package/dist/plugins/splitChunks.d.ts +4 -0
  52. package/dist/plugins/splitChunks.js +275 -0
  53. package/dist/plugins/startUrl.d.ts +3 -0
  54. package/dist/plugins/startUrl.js +111 -0
  55. package/dist/plugins/svg.d.ts +2 -0
  56. package/dist/plugins/svg.js +67 -0
  57. package/dist/plugins/target.d.ts +2 -0
  58. package/dist/plugins/target.js +56 -0
  59. package/dist/plugins/toml.d.ts +2 -0
  60. package/dist/plugins/toml.js +19 -0
  61. package/dist/plugins/wasm.d.ts +2 -0
  62. package/dist/plugins/wasm.js +34 -0
  63. package/dist/plugins/yaml.d.ts +2 -0
  64. package/dist/plugins/yaml.js +19 -0
  65. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ <p align="center">
2
+ <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
3
+ </p>
4
+
5
+ # Rsbuild
6
+
7
+ Unleash the power of Rspack with the out-of-the-box build tool.
8
+
9
+ ## Getting Started
10
+
11
+ Please follow [Quick Start](https://rsbuild.dev/guides/get-started/quick-start) to get started with Rsbuild.
12
+
13
+ ## Documentation
14
+
15
+ - [English Documentation](https://rsbuild.dev/)
16
+ - [中文文档](https://rsbuild.dev/zh)
17
+
18
+ ## Contributing
19
+
20
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
21
+
22
+ ## License
23
+
24
+ Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
@@ -0,0 +1,2 @@
1
+ import { type BuilderInstance, type BuilderProvider, type CreateBuilderOptions } from '@rsbuild/shared';
2
+ export declare function createBuilder<P extends BuilderProvider = BuilderProvider>(provider: P, options: CreateBuilderOptions): Promise<BuilderInstance<P>>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createBuilder", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createBuilder;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ const _plugins = require("./plugins");
13
+ async function createBuilder(provider, options) {
14
+ const builderOptions = (0, _shared.applyDefaultBuilderOptions)(options);
15
+ const pluginStore = (0, _shared.createPluginStore)();
16
+ const { build, serve, pluginAPI, publicContext, initConfigs, inspectConfig, createCompiler, startDevServer, applyDefaultPlugins } = await provider({
17
+ pluginStore,
18
+ builderOptions,
19
+ plugins: _plugins.plugins
20
+ });
21
+ (0, _shared.debug)("add default plugins");
22
+ await applyDefaultPlugins(pluginStore);
23
+ (0, _shared.debug)("add default plugins done");
24
+ return {
25
+ ...(0, _shared.pick)(pluginStore, [
26
+ "addPlugins",
27
+ "removePlugins",
28
+ "isPluginExists"
29
+ ]),
30
+ ...(0, _shared.pick)(pluginAPI, [
31
+ "onBeforeBuild",
32
+ "onBeforeCreateCompiler",
33
+ "onBeforeStartDevServer",
34
+ "onAfterBuild",
35
+ "onAfterCreateCompiler",
36
+ "onAfterStartDevServer",
37
+ "onDevCompileDone",
38
+ "onExit",
39
+ "getHTMLPaths",
40
+ "getBuilderConfig",
41
+ "getNormalizedConfig"
42
+ ]),
43
+ serve,
44
+ build,
45
+ createCompiler,
46
+ initConfigs,
47
+ inspectConfig,
48
+ startDevServer,
49
+ context: publicContext
50
+ };
51
+ }
@@ -0,0 +1,3 @@
1
+ export { createBuilder } from './createBuilder';
2
+ export { mergeBuilderConfig } from '@rsbuild/shared';
3
+ export type { BuilderMode, BuilderEntry, BuilderTarget, BuilderPlugin, BuilderContext, BuilderInstance, CreateBuilderOptions, InspectConfigOptions, OnExitFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnBeforeBuildFn, OnBeforeStartDevServerFn, OnBeforeCreateCompilerFn, OnDevCompileDoneFn, ModifyBuilderConfigFn } from '@rsbuild/shared';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ createBuilder: function() {
14
+ return _createBuilder.createBuilder;
15
+ },
16
+ mergeBuilderConfig: function() {
17
+ return _shared.mergeBuilderConfig;
18
+ }
19
+ });
20
+ const _createBuilder = require("./createBuilder");
21
+ const _shared = require("@rsbuild/shared");
@@ -0,0 +1,3 @@
1
+ import type { BuilderTarget, DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginAntd: () => DefaultBuilderPlugin;
3
+ export declare function useSSR(target: BuilderTarget | BuilderTarget[]): boolean;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ builderPluginAntd: function() {
14
+ return builderPluginAntd;
15
+ },
16
+ useSSR: function() {
17
+ return useSSR;
18
+ }
19
+ });
20
+ const _utils = require("@modern-js/utils");
21
+ const builderPluginAntd = () => ({
22
+ name: `builder-plugin-antd`,
23
+ setup(api) {
24
+ api.modifyBuilderConfig((builderConfig) => {
25
+ var _builderConfig_source_transformImport;
26
+ var _builderConfig;
27
+ var _source;
28
+ (_source = (_builderConfig = builderConfig).source) !== null && _source !== void 0 ? _source : _builderConfig.source = {};
29
+ if (builderConfig.source.transformImport === false || ((_builderConfig_source_transformImport = builderConfig.source.transformImport) === null || _builderConfig_source_transformImport === void 0 ? void 0 : _builderConfig_source_transformImport.some((item) => item.libraryName === "antd"))) {
30
+ return;
31
+ }
32
+ const antdMajorVersion = (0, _utils.getAntdMajorVersion)(api.context.rootPath);
33
+ if (antdMajorVersion && antdMajorVersion < 5) {
34
+ var _builderConfig1;
35
+ var _source1;
36
+ (_source1 = (_builderConfig1 = builderConfig).source) !== null && _source1 !== void 0 ? _source1 : _builderConfig1.source = {};
37
+ builderConfig.source.transformImport = [
38
+ ...builderConfig.source.transformImport || [],
39
+ {
40
+ libraryName: "antd",
41
+ libraryDirectory: useSSR(api.context.target) ? "lib" : "es",
42
+ style: true
43
+ }
44
+ ];
45
+ }
46
+ });
47
+ }
48
+ });
49
+ function useSSR(target) {
50
+ return (Array.isArray(target) ? target : [
51
+ target
52
+ ]).some((item) => [
53
+ "node",
54
+ "service-worker"
55
+ ].includes(item));
56
+ }
@@ -0,0 +1,2 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginArco: () => DefaultBuilderPlugin;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginArco", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginArco;
9
+ }
10
+ });
11
+ const _utils = require("@modern-js/utils");
12
+ const _antd = require("./antd");
13
+ const builderPluginArco = () => ({
14
+ name: `builder-plugin-arco`,
15
+ setup(api) {
16
+ const ARCO_NAME = "@arco-design/web-react";
17
+ const ARCO_ICON = `${ARCO_NAME}/icon`;
18
+ api.modifyBuilderConfig((builderConfig) => {
19
+ var _builderConfig;
20
+ const { transformImport = [] } = builderConfig.source || {};
21
+ if (transformImport === false || !(0, _utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
22
+ return;
23
+ }
24
+ const isUseSSR = (0, _antd.useSSR)(api.context.target);
25
+ if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
26
+ transformImport.push({
27
+ libraryName: ARCO_NAME,
28
+ libraryDirectory: isUseSSR ? "lib" : "es",
29
+ camelToDashComponentName: false,
30
+ style: true
31
+ });
32
+ }
33
+ if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
34
+ transformImport.push({
35
+ libraryName: ARCO_ICON,
36
+ libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
37
+ camelToDashComponentName: false
38
+ });
39
+ }
40
+ (_builderConfig = builderConfig).source || (_builderConfig.source = {});
41
+ builderConfig.source.transformImport = transformImport;
42
+ });
43
+ }
44
+ });
@@ -0,0 +1,2 @@
1
+ import type { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderAssetPlugin: (assetType: 'image' | 'media' | 'font', exts: string[]) => DefaultBuilderPlugin;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderAssetPlugin", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderAssetPlugin;
9
+ }
10
+ });
11
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
12
+ const _shared = require("@rsbuild/shared");
13
+ function _interop_require_default(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const builderAssetPlugin = (assetType, exts) => ({
19
+ name: `builder-plugin-${assetType}`,
20
+ setup(api) {
21
+ api.modifyBundlerChain((chain, { isProd }) => {
22
+ const config = api.getNormalizedConfig();
23
+ const regExp = (0, _shared.getRegExpForExts)(exts);
24
+ const distDir = (0, _shared.getDistPath)(config.output, assetType);
25
+ const filename = (0, _shared.getFilename)(config.output, assetType, isProd);
26
+ const maxSize = config.output.dataUriLimit[assetType];
27
+ const rule = chain.module.rule(assetType).test(regExp);
28
+ (0, _shared.chainStaticAssetRule)({
29
+ rule,
30
+ maxSize,
31
+ filename: _path.default.posix.join(distDir, filename),
32
+ assetType
33
+ });
34
+ });
35
+ }
36
+ });
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare function builderPluginAssetsRetry(): DefaultBuilderPlugin;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginAssetsRetry", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginAssetsRetry;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ function builderPluginAssetsRetry() {
53
+ return {
54
+ name: "builder-plugin-assets-retry",
55
+ setup(api) {
56
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin }) => {
57
+ const config = api.getNormalizedConfig();
58
+ if (!config.output.assetsRetry || (0, _shared.isHtmlDisabled)(config, target)) {
59
+ return;
60
+ }
61
+ const { AssetsRetryPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
62
+ const distDir = (0, _shared.getDistPath)(config.output, "js");
63
+ const { assetsRetry = {} } = config.output;
64
+ if (assetsRetry.crossOrigin === void 0) {
65
+ assetsRetry.crossOrigin = config.html.crossorigin;
66
+ }
67
+ chain.plugin(CHAIN_ID.PLUGIN.ASSETS_RETRY).use(AssetsRetryPlugin, [
68
+ {
69
+ ...assetsRetry,
70
+ distDir,
71
+ HtmlPlugin
72
+ }
73
+ ]);
74
+ });
75
+ }
76
+ };
77
+ }
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare function builderPluginBundleAnalyzer(): DefaultBuilderPlugin;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginBundleAnalyzer", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginBundleAnalyzer;
9
+ }
10
+ });
11
+ function _getRequireWildcardCache(nodeInterop) {
12
+ if (typeof WeakMap !== "function")
13
+ return null;
14
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
15
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
16
+ return (_getRequireWildcardCache = function(nodeInterop2) {
17
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
18
+ })(nodeInterop);
19
+ }
20
+ function _interop_require_wildcard(obj, nodeInterop) {
21
+ if (!nodeInterop && obj && obj.__esModule) {
22
+ return obj;
23
+ }
24
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
+ return {
26
+ default: obj
27
+ };
28
+ }
29
+ var cache = _getRequireWildcardCache(nodeInterop);
30
+ if (cache && cache.has(obj)) {
31
+ return cache.get(obj);
32
+ }
33
+ var newObj = {};
34
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
35
+ for (var key in obj) {
36
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
37
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
38
+ if (desc && (desc.get || desc.set)) {
39
+ Object.defineProperty(newObj, key, desc);
40
+ } else {
41
+ newObj[key] = obj[key];
42
+ }
43
+ }
44
+ }
45
+ newObj.default = obj;
46
+ if (cache) {
47
+ cache.set(obj, newObj);
48
+ }
49
+ return newObj;
50
+ }
51
+ function builderPluginBundleAnalyzer() {
52
+ return {
53
+ name: "builder-plugin-bundle-analyzer",
54
+ setup(api) {
55
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, target }) => {
56
+ const config = api.getNormalizedConfig();
57
+ if (!process.env.BUNDLE_ANALYZE && !config.performance.bundleAnalyze) {
58
+ return;
59
+ }
60
+ const { default: BundleAnalyzer } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared/webpack-bundle-analyzer")));
61
+ chain.plugin(CHAIN_ID.PLUGIN.BUNDLE_ANALYZER).use(BundleAnalyzer.BundleAnalyzerPlugin, [
62
+ {
63
+ analyzerMode: "static",
64
+ openAnalyzer: false,
65
+ reportFilename: `report-${target}.html`,
66
+ ...config.performance.bundleAnalyze || {}
67
+ }
68
+ ]);
69
+ });
70
+ }
71
+ };
72
+ }
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare const builderPluginCache: () => DefaultBuilderPlugin;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginCache", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginCache;
9
+ }
10
+ });
11
+ const _crypto = /* @__PURE__ */ _interop_require_default(require("crypto"));
12
+ const _path = require("path");
13
+ const _shared = require("@rsbuild/shared");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ function _getRequireWildcardCache(nodeInterop) {
20
+ if (typeof WeakMap !== "function")
21
+ return null;
22
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
23
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
24
+ return (_getRequireWildcardCache = function(nodeInterop2) {
25
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
26
+ })(nodeInterop);
27
+ }
28
+ function _interop_require_wildcard(obj, nodeInterop) {
29
+ if (!nodeInterop && obj && obj.__esModule) {
30
+ return obj;
31
+ }
32
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
33
+ return {
34
+ default: obj
35
+ };
36
+ }
37
+ var cache = _getRequireWildcardCache(nodeInterop);
38
+ if (cache && cache.has(obj)) {
39
+ return cache.get(obj);
40
+ }
41
+ var newObj = {};
42
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
43
+ for (var key in obj) {
44
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
45
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
46
+ if (desc && (desc.get || desc.set)) {
47
+ Object.defineProperty(newObj, key, desc);
48
+ } else {
49
+ newObj[key] = obj[key];
50
+ }
51
+ }
52
+ }
53
+ newObj.default = obj;
54
+ if (cache) {
55
+ cache.set(obj, newObj);
56
+ }
57
+ return newObj;
58
+ }
59
+ async function validateCache(cacheDirectory, buildDependencies) {
60
+ const { fs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
61
+ const configFile = (0, _path.join)(cacheDirectory, "buildDependencies.json");
62
+ if (await (0, _shared.isFileExists)(configFile)) {
63
+ const prevBuildDependencies = await fs.readJSON(configFile);
64
+ if (JSON.stringify(prevBuildDependencies) === JSON.stringify(buildDependencies)) {
65
+ return;
66
+ }
67
+ await fs.remove(cacheDirectory);
68
+ }
69
+ await fs.outputJSON(configFile, buildDependencies);
70
+ }
71
+ function getDigestHash(digest) {
72
+ const fsHash = _crypto.default.createHash("md5");
73
+ const md5 = fsHash.update(JSON.stringify(digest)).digest("hex").slice(0, 8);
74
+ return md5;
75
+ }
76
+ function getCacheDirectory({ cacheDirectory }, context) {
77
+ if (cacheDirectory) {
78
+ return (0, _path.isAbsolute)(cacheDirectory) ? cacheDirectory : (0, _path.join)(context.rootPath, cacheDirectory);
79
+ }
80
+ return (0, _path.join)(context.cachePath, context.bundlerType);
81
+ }
82
+ async function getBuildDependencies(context) {
83
+ const { findExists } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@modern-js/utils")));
84
+ const rootPackageJson = (0, _path.join)(context.rootPath, "package.json");
85
+ const browserslistConfig = (0, _path.join)(context.rootPath, ".browserslistrc");
86
+ const buildDependencies = {};
87
+ if (await (0, _shared.isFileExists)(rootPackageJson)) {
88
+ buildDependencies.packageJson = [
89
+ rootPackageJson
90
+ ];
91
+ }
92
+ if (context.configPath) {
93
+ buildDependencies.config = [
94
+ context.configPath
95
+ ];
96
+ }
97
+ if (context.tsconfigPath) {
98
+ buildDependencies.tsconfig = [
99
+ context.tsconfigPath
100
+ ];
101
+ }
102
+ if (await (0, _shared.isFileExists)(browserslistConfig)) {
103
+ buildDependencies.browserslistrc = [
104
+ browserslistConfig
105
+ ];
106
+ }
107
+ const tailwindExts = [
108
+ "ts",
109
+ "js",
110
+ "cjs",
111
+ "mjs"
112
+ ];
113
+ const configs = tailwindExts.map((ext) => (0, _path.join)(context.rootPath, `tailwind.config.${ext}`));
114
+ const tailwindConfig = findExists(configs);
115
+ if (tailwindConfig) {
116
+ buildDependencies.tailwindcss = [
117
+ tailwindConfig
118
+ ];
119
+ }
120
+ return buildDependencies;
121
+ }
122
+ const builderPluginCache = () => ({
123
+ name: "builder-plugin-cache",
124
+ setup(api) {
125
+ api.modifyBundlerChain(async (chain, { target, env }) => {
126
+ const { buildCache } = api.getNormalizedConfig().performance;
127
+ if (buildCache === false) {
128
+ chain.cache(false);
129
+ return;
130
+ }
131
+ const { context } = api;
132
+ const cacheConfig = typeof buildCache === "boolean" ? {} : buildCache;
133
+ const cacheDirectory = getCacheDirectory(cacheConfig, context);
134
+ const buildDependencies = await getBuildDependencies(context);
135
+ await validateCache(cacheDirectory, buildDependencies);
136
+ const useDigest = Array.isArray(cacheConfig.cacheDigest) && cacheConfig.cacheDigest.length;
137
+ chain.cache({
138
+ // The default cache name of webpack is '${name}-${env}', and the `name` is `default` by default.
139
+ // We set cache name to avoid cache conflicts of different targets.
140
+ name: useDigest ? `${target}-${env}-${getDigestHash(cacheConfig.cacheDigest)}` : `${target}-${env}`,
141
+ type: "filesystem",
142
+ cacheDirectory,
143
+ buildDependencies
144
+ });
145
+ });
146
+ }
147
+ });
@@ -0,0 +1,2 @@
1
+ import { DefaultBuilderPlugin } from '@rsbuild/shared';
2
+ export declare function builderPluginCheckSyntax(): DefaultBuilderPlugin;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginCheckSyntax", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginCheckSyntax;
9
+ }
10
+ });
11
+ const _shared = require("@rsbuild/shared");
12
+ function _getRequireWildcardCache(nodeInterop) {
13
+ if (typeof WeakMap !== "function")
14
+ return null;
15
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
16
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
17
+ return (_getRequireWildcardCache = function(nodeInterop2) {
18
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
19
+ })(nodeInterop);
20
+ }
21
+ function _interop_require_wildcard(obj, nodeInterop) {
22
+ if (!nodeInterop && obj && obj.__esModule) {
23
+ return obj;
24
+ }
25
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
26
+ return {
27
+ default: obj
28
+ };
29
+ }
30
+ var cache = _getRequireWildcardCache(nodeInterop);
31
+ if (cache && cache.has(obj)) {
32
+ return cache.get(obj);
33
+ }
34
+ var newObj = {};
35
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
36
+ for (var key in obj) {
37
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
38
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
39
+ if (desc && (desc.get || desc.set)) {
40
+ Object.defineProperty(newObj, key, desc);
41
+ } else {
42
+ newObj[key] = obj[key];
43
+ }
44
+ }
45
+ }
46
+ newObj.default = obj;
47
+ if (cache) {
48
+ cache.set(obj, newObj);
49
+ }
50
+ return newObj;
51
+ }
52
+ function builderPluginCheckSyntax() {
53
+ return {
54
+ name: "builder-plugin-check-syntax",
55
+ setup(api) {
56
+ api.modifyBundlerChain(async (chain, { isProd, target }) => {
57
+ const config = api.getNormalizedConfig();
58
+ const { checkSyntax } = config.security;
59
+ if (!isProd || [
60
+ "node",
61
+ "web-worker"
62
+ ].includes(target) || !checkSyntax) {
63
+ return;
64
+ }
65
+ const targets = await getCheckTargets(api.context, config, target, checkSyntax);
66
+ const { CheckSyntaxPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard(require("@rsbuild/shared")));
67
+ chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
68
+ {
69
+ targets,
70
+ rootPath: api.context.rootPath,
71
+ ...typeof checkSyntax === "object" ? checkSyntax : {}
72
+ }
73
+ ]);
74
+ });
75
+ }
76
+ };
77
+ }
78
+ async function getCheckTargets(builderContext, builderConfig, builderTarget, checkSyntax) {
79
+ var _ref;
80
+ const browserslist = (_ref = await (0, _shared.getBrowserslistWithDefault)(builderContext.rootPath, builderConfig, builderTarget)) !== null && _ref !== void 0 ? _ref : _shared.DEFAULT_BROWSERSLIST[builderTarget];
81
+ if (checkSyntax === true) {
82
+ return browserslist;
83
+ }
84
+ var _checkSyntax_targets;
85
+ return (_checkSyntax_targets = checkSyntax.targets) !== null && _checkSyntax_targets !== void 0 ? _checkSyntax_targets : browserslist;
86
+ }