@modern-js/builder 2.25.2 → 2.27.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/createBuilder.d.ts +1 -1
  3. package/dist/createBuilder.js +48 -38
  4. package/dist/index.d.ts +2 -1
  5. package/dist/index.js +24 -6
  6. package/dist/plugins/antd.d.ts +1 -1
  7. package/dist/plugins/antd.js +52 -30
  8. package/dist/plugins/arco.d.ts +1 -1
  9. package/dist/plugins/arco.js +43 -35
  10. package/dist/plugins/asset.d.ts +1 -1
  11. package/dist/plugins/asset.js +29 -25
  12. package/dist/plugins/assetsRetry.d.ts +1 -1
  13. package/dist/plugins/assetsRetry.js +34 -51
  14. package/dist/plugins/bundleAnalyzer.d.ts +1 -1
  15. package/dist/plugins/bundleAnalyzer.js +29 -50
  16. package/dist/plugins/cache.d.ts +1 -1
  17. package/dist/plugins/cache.js +68 -87
  18. package/dist/plugins/checkSyntax.d.ts +1 -1
  19. package/dist/plugins/checkSyntax.js +40 -54
  20. package/dist/plugins/cleanOutput.d.ts +1 -1
  21. package/dist/plugins/cleanOutput.js +22 -38
  22. package/dist/plugins/devtool.d.ts +1 -1
  23. package/dist/plugins/devtool.js +23 -21
  24. package/dist/plugins/entry.d.ts +1 -1
  25. package/dist/plugins/entry.js +23 -19
  26. package/dist/plugins/externals.d.ts +1 -1
  27. package/dist/plugins/externals.js +28 -25
  28. package/dist/plugins/fileSize.d.ts +1 -1
  29. package/dist/plugins/fileSize.js +124 -130
  30. package/dist/plugins/html.d.ts +1 -1
  31. package/dist/plugins/html.js +203 -206
  32. package/dist/plugins/index.d.ts +1 -1
  33. package/dist/plugins/index.js +40 -52
  34. package/dist/plugins/inlineChunk.d.ts +1 -1
  35. package/dist/plugins/inlineChunk.js +50 -59
  36. package/dist/plugins/moment.d.ts +1 -1
  37. package/dist/plugins/moment.js +23 -20
  38. package/dist/plugins/rem.d.ts +1 -1
  39. package/dist/plugins/rem.js +74 -97
  40. package/dist/plugins/sourceBuild.d.ts +23 -0
  41. package/dist/plugins/sourceBuild.js +137 -0
  42. package/dist/plugins/splitChunks.d.ts +1 -1
  43. package/dist/plugins/splitChunks.js +206 -229
  44. package/dist/plugins/startUrl.d.ts +1 -1
  45. package/dist/plugins/startUrl.js +62 -78
  46. package/dist/plugins/svg.d.ts +1 -1
  47. package/dist/plugins/svg.js +64 -81
  48. package/dist/plugins/target.d.ts +1 -1
  49. package/dist/plugins/target.js +52 -31
  50. package/dist/plugins/toml.d.ts +1 -1
  51. package/dist/plugins/toml.js +16 -15
  52. package/dist/plugins/tsChecker.d.ts +1 -1
  53. package/dist/plugins/tsChecker.js +69 -92
  54. package/dist/plugins/wasm.d.ts +1 -1
  55. package/dist/plugins/wasm.js +31 -32
  56. package/dist/plugins/yaml.d.ts +1 -1
  57. package/dist/plugins/yaml.js +16 -15
  58. package/package.json +11 -6
@@ -1,63 +1,54 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
17
4
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.builderPluginInlineChunk = void 0;
27
- const builder_shared_1 = require("@modern-js/builder-shared");
5
+ Object.defineProperty(exports, "builderPluginInlineChunk", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginInlineChunk;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _buildershared = require("@modern-js/builder-shared");
28
13
  const builderPluginInlineChunk = () => ({
29
- name: 'builder-plugin-inline-chunk',
30
- setup(api) {
31
- api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
32
- const config = api.getNormalizedConfig();
33
- if ((0, builder_shared_1.isHtmlDisabled)(config, target) || !isProd) {
34
- return;
35
- }
36
- const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
37
- const { disableInlineRuntimeChunk, enableInlineStyles,
38
- // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
39
- enableInlineScripts, } = config.output;
40
- const tests = [];
41
- if (enableInlineScripts) {
42
- tests.push(enableInlineScripts === true ? /\.js$/ : enableInlineScripts);
43
- }
44
- if (enableInlineStyles) {
45
- tests.push(enableInlineStyles === true ? /\.css$/ : enableInlineStyles);
46
- }
47
- if (!disableInlineRuntimeChunk) {
48
- tests.push(
49
- // RegExp like /builder-runtime([.].+)?\.js$/
50
- // matches builder-runtime.js and builder-runtime.123456.js
51
- new RegExp(`${builder_shared_1.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`));
52
- }
53
- chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
54
- HtmlPlugin,
55
- {
56
- tests,
57
- distPath: (0, builder_shared_1.pick)(config.output.distPath, ['js', 'css']),
58
- },
59
- ]);
60
- });
61
- },
14
+ name: "builder-plugin-inline-chunk",
15
+ setup(api) {
16
+ api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin }) => {
17
+ const config = api.getNormalizedConfig();
18
+ if ((0, _buildershared.isHtmlDisabled)(config, target) || !isProd) {
19
+ return;
20
+ }
21
+ const { InlineChunkHtmlPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/builder-shared")));
22
+ const {
23
+ disableInlineRuntimeChunk,
24
+ enableInlineStyles,
25
+ // todo: not support enableInlineScripts in Rspack yet, which will take unknown build error
26
+ enableInlineScripts
27
+ } = config.output;
28
+ const tests = [];
29
+ if (enableInlineScripts) {
30
+ tests.push(enableInlineScripts === true ? /\.js$/ : enableInlineScripts);
31
+ }
32
+ if (enableInlineStyles) {
33
+ tests.push(enableInlineStyles === true ? /\.css$/ : enableInlineStyles);
34
+ }
35
+ if (!disableInlineRuntimeChunk) {
36
+ tests.push(
37
+ // RegExp like /builder-runtime([.].+)?\.js$/
38
+ // matches builder-runtime.js and builder-runtime.123456.js
39
+ new RegExp(`${_buildershared.RUNTIME_CHUNK_NAME}([.].+)?\\.js$`)
40
+ );
41
+ }
42
+ chain.plugin(CHAIN_ID.PLUGIN.INLINE_HTML).use(InlineChunkHtmlPlugin, [
43
+ HtmlPlugin,
44
+ {
45
+ tests,
46
+ distPath: (0, _buildershared.pick)(config.output.distPath, [
47
+ "js",
48
+ "css"
49
+ ])
50
+ }
51
+ ]);
52
+ });
53
+ }
62
54
  });
63
- exports.builderPluginInlineChunk = builderPluginInlineChunk;
@@ -1,2 +1,2 @@
1
1
  import { DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginMoment: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginMoment: () => DefaultBuilderPlugin;
@@ -1,23 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.builderPluginMoment = void 0;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginMoment", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginMoment;
9
+ }
10
+ });
4
11
  const builderPluginMoment = () => ({
5
- name: 'builder-plugin-moment',
6
- setup(api) {
7
- api.modifyBundlerChain(async (chain, { webpack }) => {
8
- const config = api.getNormalizedConfig();
9
- if (config.performance.removeMomentLocale) {
10
- // Moment.js includes a lots of locale data by default.
11
- // We can using IgnorePlugin to allow the user to opt into importing specific locales.
12
- // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
13
- chain.plugin('remove-moment-locale').use(webpack.IgnorePlugin, [
14
- {
15
- resourceRegExp: /^\.\/locale$/,
16
- contextRegExp: /moment$/,
17
- },
18
- ]);
19
- }
20
- });
21
- },
12
+ name: "builder-plugin-moment",
13
+ setup(api) {
14
+ api.modifyBundlerChain(async (chain, { webpack }) => {
15
+ const config = api.getNormalizedConfig();
16
+ if (config.performance.removeMomentLocale) {
17
+ chain.plugin("remove-moment-locale").use(webpack.IgnorePlugin, [
18
+ {
19
+ resourceRegExp: /^\.\/locale$/,
20
+ contextRegExp: /moment$/
21
+ }
22
+ ]);
23
+ }
24
+ });
25
+ }
22
26
  });
23
- exports.builderPluginMoment = builderPluginMoment;
@@ -1,2 +1,2 @@
1
1
  import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
- export declare const builderPluginRem: () => DefaultBuilderPlugin;
2
+ export declare const builderPluginRem: () => DefaultBuilderPlugin;
@@ -1,106 +1,83 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
17
4
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.builderPluginRem = void 0;
30
- const lodash_1 = __importDefault(require("@modern-js/utils/lodash"));
31
- const builder_shared_1 = require("@modern-js/builder-shared");
5
+ Object.defineProperty(exports, "builderPluginRem", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginRem;
9
+ }
10
+ });
11
+ const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
+ const _lodash = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/lodash"));
14
+ const _buildershared = require("@modern-js/builder-shared");
32
15
  const defaultOptions = {
33
- enableRuntime: true,
34
- rootFontSize: 50,
16
+ enableRuntime: true,
17
+ rootFontSize: 50
35
18
  };
36
- const builderPluginRem = () => ({
37
- name: 'builder-plugin-rem',
19
+ const builderPluginRem = () => {
20
+ return {
21
+ name: "builder-plugin-rem",
38
22
  pre: [
39
- 'builder-plugin-css',
40
- 'builder-plugin-less',
41
- 'builder-plugin-sass',
42
- 'builder-plugin-stylus',
23
+ "builder-plugin-css",
24
+ "builder-plugin-less",
25
+ "builder-plugin-sass",
26
+ "builder-plugin-stylus"
43
27
  ],
44
28
  setup(api) {
45
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
46
- const config = api.getNormalizedConfig();
47
- const { output: { convertToRem }, } = config;
48
- if (!convertToRem || isServer || isWebWorker) {
49
- return;
50
- }
51
- const userOptions = {
52
- ...defaultOptions,
53
- ...(typeof convertToRem === 'boolean' ? {} : convertToRem),
29
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
30
+ const config = api.getNormalizedConfig();
31
+ const { output: { convertToRem } } = config;
32
+ if (!convertToRem || isServer || isWebWorker) {
33
+ return;
34
+ }
35
+ const userOptions = {
36
+ ...defaultOptions,
37
+ ...typeof convertToRem === "boolean" ? {} : convertToRem
38
+ };
39
+ const { default: PxToRemPlugin } = await Promise.resolve((0, _buildershared.getSharedPkgCompiledPath)("postcss-pxtorem")).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
40
+ const applyRules = [
41
+ CHAIN_ID.RULE.CSS,
42
+ CHAIN_ID.RULE.LESS,
43
+ CHAIN_ID.RULE.SASS,
44
+ CHAIN_ID.RULE.STYLUS
45
+ ];
46
+ const getPxToRemPlugin = () => PxToRemPlugin({
47
+ rootValue: userOptions.rootFontSize,
48
+ unitPrecision: 5,
49
+ propList: [
50
+ "*"
51
+ ],
52
+ ..._lodash.default.cloneDeep(userOptions.pxtorem || {})
53
+ });
54
+ applyRules.forEach((name) => {
55
+ chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
56
+ var _options_postcssOptions;
57
+ return {
58
+ ...options,
59
+ postcssOptions: {
60
+ ...options.postcssOptions || {},
61
+ plugins: [
62
+ ...((_options_postcssOptions = options.postcssOptions) === null || _options_postcssOptions === void 0 ? void 0 : _options_postcssOptions.plugins) || [],
63
+ getPxToRemPlugin()
64
+ ]
65
+ }
54
66
  };
55
- // handle css
56
- const { default: PxToRemPlugin } = (await Promise.resolve(`${(0, builder_shared_1.getSharedPkgCompiledPath)('postcss-pxtorem')}`).then(s => __importStar(require(s))));
57
- const applyRules = [
58
- CHAIN_ID.RULE.CSS,
59
- CHAIN_ID.RULE.LESS,
60
- CHAIN_ID.RULE.SASS,
61
- CHAIN_ID.RULE.STYLUS,
62
- ];
63
- const getPxToRemPlugin = () => PxToRemPlugin({
64
- rootValue: userOptions.rootFontSize,
65
- unitPrecision: 5,
66
- propList: ['*'],
67
- ...lodash_1.default.cloneDeep(userOptions.pxtorem || {}),
68
- });
69
- // Deep copy options to prevent unexpected behavior.
70
- applyRules.forEach(name => {
71
- chain.module.rules.has(name) &&
72
- chain.module
73
- .rule(name)
74
- .use(CHAIN_ID.USE.POSTCSS)
75
- .tap((options = {}) => {
76
- var _a;
77
- return ({
78
- ...options,
79
- postcssOptions: {
80
- ...(options.postcssOptions || {}),
81
- plugins: [
82
- ...(((_a = options.postcssOptions) === null || _a === void 0 ? void 0 : _a.plugins) || []),
83
- getPxToRemPlugin(),
84
- ],
85
- },
86
- });
87
- });
88
- });
89
- // handle runtime (html)
90
- if (!userOptions.enableRuntime) {
91
- return;
92
- }
93
- const entries = Object.keys(chain.entryPoints.entries() || {});
94
- const distDir = (0, builder_shared_1.getDistPath)(config.output, 'js');
95
- chain
96
- .plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE)
97
- .use(builder_shared_1.AutoSetRootFontSizePlugin, [
98
- userOptions,
99
- entries,
100
- HtmlPlugin,
101
- distDir,
102
- ]);
67
+ });
103
68
  });
104
- },
105
- });
106
- exports.builderPluginRem = builderPluginRem;
69
+ if (!userOptions.enableRuntime) {
70
+ return;
71
+ }
72
+ const entries = Object.keys(chain.entryPoints.entries() || {});
73
+ const distDir = (0, _buildershared.getDistPath)(config.output, "js");
74
+ chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(_buildershared.AutoSetRootFontSizePlugin, [
75
+ userOptions,
76
+ entries,
77
+ HtmlPlugin,
78
+ distDir
79
+ ]);
80
+ });
81
+ }
82
+ };
83
+ };
@@ -0,0 +1,23 @@
1
+ import type { BuilderPlugin } from '@modern-js/builder-shared';
2
+ import type { BuilderPluginAPI as WebpackBuilderPluginAPI } from '@modern-js/builder-webpack-provider';
3
+ import type { BuilderPluginAPI as RspackBuilderPluginAPI } from '@modern-js/builder-rspack-provider';
4
+ import { type ExtraMonorepoStrategies } from '@modern-js/monorepo-utils';
5
+ export declare const pluginName = "builder-plugin-source-build";
6
+ export declare const getSourceInclude: (options: {
7
+ projectNameOrRootPath: string;
8
+ findMonorepoStartPath: string;
9
+ sourceField: string;
10
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
11
+ }) => Promise<string[]>;
12
+ export declare const sourceBuildInWebpack: (api: WebpackBuilderPluginAPI, options: {
13
+ sourceField: string;
14
+ projectRootPath: string;
15
+ projectName?: string;
16
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
17
+ }) => void;
18
+ export interface PluginSourceBuildOptions {
19
+ projectName?: string;
20
+ sourceField?: string;
21
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
22
+ }
23
+ export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
@@ -0,0 +1,137 @@
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
+ pluginName: function() {
14
+ return pluginName;
15
+ },
16
+ getSourceInclude: function() {
17
+ return getSourceInclude;
18
+ },
19
+ sourceBuildInWebpack: function() {
20
+ return sourceBuildInWebpack;
21
+ },
22
+ builderPluginSourceBuild: function() {
23
+ return builderPluginSourceBuild;
24
+ }
25
+ });
26
+ const _monorepoutils = require("@modern-js/monorepo-utils");
27
+ const pluginName = "builder-plugin-source-build";
28
+ const getSourceInclude = async (options) => {
29
+ const { projectNameOrRootPath, sourceField, extraMonorepoStrategies, findMonorepoStartPath } = options;
30
+ const projects = await (0, _monorepoutils.getDependentProjects)(projectNameOrRootPath, {
31
+ cwd: findMonorepoStartPath,
32
+ recursive: true,
33
+ filter: (0, _monorepoutils.filterByField)(sourceField),
34
+ extraMonorepoStrategies
35
+ });
36
+ const includes = [];
37
+ for (const project of projects) {
38
+ includes.push(...project.getSourceEntryPaths({
39
+ field: sourceField
40
+ }));
41
+ }
42
+ return includes;
43
+ };
44
+ const sourceBuildInWebpack = (api, options) => {
45
+ const { sourceField, projectRootPath, projectName, extraMonorepoStrategies } = options;
46
+ api.modifyBuilderConfig(async (config) => {
47
+ var _config_experiments;
48
+ const { sourceBuild = true } = (_config_experiments = config.experiments) !== null && _config_experiments !== void 0 ? _config_experiments : {};
49
+ if (!sourceBuild) {
50
+ return;
51
+ }
52
+ const includes = await getSourceInclude({
53
+ projectNameOrRootPath: projectName || projectRootPath,
54
+ sourceField,
55
+ findMonorepoStartPath: projectRootPath,
56
+ extraMonorepoStrategies
57
+ });
58
+ var _config_source;
59
+ config.source = (_config_source = config.source) !== null && _config_source !== void 0 ? _config_source : {};
60
+ var _config_source_include;
61
+ config.source.include = [
62
+ ...(_config_source_include = config.source.include) !== null && _config_source_include !== void 0 ? _config_source_include : [],
63
+ ...includes
64
+ ];
65
+ });
66
+ api.modifyBundlerChain((chain) => {
67
+ const { experiments: { sourceBuild } } = api.getNormalizedConfig();
68
+ if (!sourceBuild) {
69
+ return;
70
+ }
71
+ if (chain.resolve.mainFields.values().length === 0) {
72
+ chain.resolve.mainFields.prepend("...");
73
+ chain.resolve.mainFields.prepend(sourceField);
74
+ }
75
+ });
76
+ api.modifyWebpackConfig(async (config) => {
77
+ const { experiments: { sourceBuild } } = api.getNormalizedConfig();
78
+ if (!sourceBuild) {
79
+ return;
80
+ }
81
+ var _config_resolve;
82
+ config.resolve = (_config_resolve = config.resolve) !== null && _config_resolve !== void 0 ? _config_resolve : {};
83
+ var _config_resolve_conditionNames;
84
+ config.resolve.conditionNames = [
85
+ "...",
86
+ sourceField,
87
+ ...(_config_resolve_conditionNames = config.resolve.conditionNames) !== null && _config_resolve_conditionNames !== void 0 ? _config_resolve_conditionNames : []
88
+ ];
89
+ });
90
+ };
91
+ function builderPluginSourceBuild(options) {
92
+ const { projectName, sourceField = "source", extraMonorepoStrategies } = options !== null && options !== void 0 ? options : {};
93
+ return {
94
+ name: pluginName,
95
+ async setup(api) {
96
+ const projectRootPath = api.context.rootPath;
97
+ if (api.context.bundlerType === "webpack") {
98
+ api.modifyBuilderConfig(async (config) => {
99
+ var _config_experiments;
100
+ const { sourceBuild = true } = (_config_experiments = config.experiments) !== null && _config_experiments !== void 0 ? _config_experiments : {};
101
+ if (!sourceBuild) {
102
+ return;
103
+ }
104
+ const includes = await getSourceInclude({
105
+ projectNameOrRootPath: projectName || projectRootPath,
106
+ sourceField,
107
+ findMonorepoStartPath: projectRootPath,
108
+ extraMonorepoStrategies
109
+ });
110
+ var _config_source;
111
+ config.source = (_config_source = config.source) !== null && _config_source !== void 0 ? _config_source : {};
112
+ var _config_source_include;
113
+ config.source.include = [
114
+ ...(_config_source_include = config.source.include) !== null && _config_source_include !== void 0 ? _config_source_include : [],
115
+ ...includes
116
+ ];
117
+ });
118
+ api.modifyBundlerChain((chain, { CHAIN_ID }) => {
119
+ const { experiments: { sourceBuild } } = api.getNormalizedConfig();
120
+ if (!sourceBuild) {
121
+ return;
122
+ }
123
+ chain.module.rule(CHAIN_ID.RULE.JS).resolve.mainFields.merge([
124
+ "...",
125
+ sourceField
126
+ ]);
127
+ chain.module.rule(CHAIN_ID.RULE.JS).resolve.merge({
128
+ conditionNames: [
129
+ "...",
130
+ sourceField
131
+ ]
132
+ });
133
+ });
134
+ }
135
+ }
136
+ };
137
+ }
@@ -1,4 +1,4 @@
1
1
  import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
2
  /** Expect to match path just like "./node_modules/react-router/" */
3
3
  export declare const createDependenciesRegExp: (...dependencies: (string | RegExp)[]) => RegExp;
4
- export declare function builderPluginSplitChunks(): DefaultBuilderPlugin;
4
+ export declare function builderPluginSplitChunks(): DefaultBuilderPlugin;