@modern-js/builder 2.26.0 → 2.28.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 (60) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/createBuilder.d.ts +1 -1
  3. package/dist/createBuilder.js +48 -38
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +24 -8
  6. package/dist/plugins/antd.d.ts +1 -1
  7. package/dist/plugins/antd.js +51 -31
  8. package/dist/plugins/arco.d.ts +1 -1
  9. package/dist/plugins/arco.js +41 -34
  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 +204 -206
  32. package/dist/plugins/index.d.ts +1 -1
  33. package/dist/plugins/index.js +41 -53
  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/nodeAddons.d.ts +2 -0
  39. package/dist/plugins/nodeAddons.js +48 -0
  40. package/dist/plugins/rem.d.ts +1 -1
  41. package/dist/plugins/rem.js +73 -98
  42. package/dist/plugins/sourceBuild.d.ts +8 -14
  43. package/dist/plugins/sourceBuild.js +81 -111
  44. package/dist/plugins/splitChunks.d.ts +1 -1
  45. package/dist/plugins/splitChunks.js +206 -229
  46. package/dist/plugins/startUrl.d.ts +1 -1
  47. package/dist/plugins/startUrl.js +62 -78
  48. package/dist/plugins/svg.d.ts +1 -1
  49. package/dist/plugins/svg.js +64 -81
  50. package/dist/plugins/target.d.ts +1 -1
  51. package/dist/plugins/target.js +52 -31
  52. package/dist/plugins/toml.d.ts +1 -1
  53. package/dist/plugins/toml.js +16 -15
  54. package/dist/plugins/tsChecker.d.ts +1 -1
  55. package/dist/plugins/tsChecker.js +79 -92
  56. package/dist/plugins/wasm.d.ts +1 -1
  57. package/dist/plugins/wasm.js +31 -32
  58. package/dist/plugins/yaml.d.ts +1 -1
  59. package/dist/plugins/yaml.js +16 -15
  60. package/package.json +11 -9
@@ -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;
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ export declare const builderPluginNodeAddons: () => DefaultBuilderPlugin;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginNodeAddons", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginNodeAddons;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _buildershared = require("@modern-js/builder-shared");
13
+ const builderPluginNodeAddons = () => ({
14
+ name: "builder-plugin-node-addons",
15
+ setup(api) {
16
+ api.modifyBundlerChain(async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
17
+ if (!isServer && !isServiceWorker) {
18
+ return;
19
+ }
20
+ const { chalk, pkgUp } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
21
+ const getDistName = (resource) => {
22
+ const pkgJSON = pkgUp.sync({
23
+ cwd: resource
24
+ });
25
+ if (!pkgJSON) {
26
+ throw new Error(`Failed to compile Node.js addons, couldn't find the package.json of ${chalk.yellow(resource)}.`);
27
+ }
28
+ const getFilename = (resource2, pkgName2) => {
29
+ var _match;
30
+ const reg = new RegExp(`node_modules/${pkgName2}/(.+)`);
31
+ const match = resource2.match(reg);
32
+ const filename = (_match = match) === null || _match === void 0 ? void 0 : _match[1];
33
+ if (!filename) {
34
+ return "[name].[ext]";
35
+ }
36
+ return `${filename}`;
37
+ };
38
+ const { name: pkgName } = require(pkgJSON);
39
+ const config = api.getNormalizedConfig();
40
+ const serverPath = (0, _buildershared.getDistPath)(config.output, "server");
41
+ return `${serverPath}/${getFilename(resource, pkgName)}`;
42
+ };
43
+ chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, _buildershared.getSharedPkgCompiledPath)("node-loader")).options({
44
+ name: getDistName
45
+ });
46
+ });
47
+ }
48
+ });
@@ -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,81 @@
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
19
  const builderPluginRem = () => ({
37
- name: 'builder-plugin-rem',
38
- pre: [
39
- 'builder-plugin-css',
40
- 'builder-plugin-less',
41
- 'builder-plugin-sass',
42
- 'builder-plugin-stylus',
43
- ],
44
- 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),
54
- };
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;
20
+ name: "builder-plugin-rem",
21
+ pre: [
22
+ "builder-plugin-css",
23
+ "builder-plugin-less",
24
+ "builder-plugin-sass",
25
+ "builder-plugin-stylus"
26
+ ],
27
+ setup(api) {
28
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
29
+ const config = api.getNormalizedConfig();
30
+ const { output: { convertToRem } } = config;
31
+ if (!convertToRem || isServer || isWebWorker) {
32
+ return;
33
+ }
34
+ const userOptions = {
35
+ ...defaultOptions,
36
+ ...typeof convertToRem === "boolean" ? {} : convertToRem
37
+ };
38
+ const { default: PxToRemPlugin } = await Promise.resolve((0, _buildershared.getSharedPkgCompiledPath)("postcss-pxtorem")).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
39
+ const applyRules = [
40
+ CHAIN_ID.RULE.CSS,
41
+ CHAIN_ID.RULE.LESS,
42
+ CHAIN_ID.RULE.SASS,
43
+ CHAIN_ID.RULE.STYLUS
44
+ ];
45
+ const getPxToRemPlugin = () => PxToRemPlugin({
46
+ rootValue: userOptions.rootFontSize,
47
+ unitPrecision: 5,
48
+ propList: [
49
+ "*"
50
+ ],
51
+ ..._lodash.default.cloneDeep(userOptions.pxtorem || {})
52
+ });
53
+ applyRules.forEach((name) => {
54
+ chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
55
+ var _options_postcssOptions;
56
+ return {
57
+ ...options,
58
+ postcssOptions: {
59
+ ...options.postcssOptions || {},
60
+ plugins: [
61
+ ...((_options_postcssOptions = options.postcssOptions) === null || _options_postcssOptions === void 0 ? void 0 : _options_postcssOptions.plugins) || [],
62
+ getPxToRemPlugin()
63
+ ]
92
64
  }
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
- ]);
65
+ };
103
66
  });
104
- },
67
+ });
68
+ if (!userOptions.enableRuntime) {
69
+ return;
70
+ }
71
+ const entries = Object.keys(chain.entryPoints.entries() || {});
72
+ const distDir = (0, _buildershared.getDistPath)(config.output, "js");
73
+ chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(_buildershared.AutoSetRootFontSizePlugin, [
74
+ userOptions,
75
+ entries,
76
+ HtmlPlugin,
77
+ distDir
78
+ ]);
79
+ });
80
+ }
105
81
  });
106
- exports.builderPluginRem = builderPluginRem;
@@ -4,20 +4,14 @@ import type { BuilderPluginAPI as RspackBuilderPluginAPI } from '@modern-js/buil
4
4
  import { type ExtraMonorepoStrategies } from '@modern-js/monorepo-utils';
5
5
  export declare const pluginName = "builder-plugin-source-build";
6
6
  export declare const getSourceInclude: (options: {
7
- projectNameOrRootPath: string;
8
- findMonorepoStartPath: string;
9
- sourceField: string;
10
- extraMonorepoStrategies?: ExtraMonorepoStrategies;
7
+ projectNameOrRootPath: string;
8
+ findMonorepoStartPath: string;
9
+ sourceField: string;
10
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
11
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
12
  export interface PluginSourceBuildOptions {
19
- projectName?: string;
20
- sourceField?: string;
21
- extraMonorepoStrategies?: ExtraMonorepoStrategies;
13
+ projectName?: string;
14
+ sourceField?: string;
15
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
22
16
  }
23
- export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
17
+ export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
@@ -1,121 +1,91 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.builderPluginSourceBuild = exports.sourceBuildInWebpack = exports.getSourceInclude = exports.pluginName = void 0;
4
- const monorepo_utils_1 = require("@modern-js/monorepo-utils");
5
- exports.pluginName = 'builder-plugin-source-build';
6
- const getSourceInclude = async (options) => {
7
- const { projectNameOrRootPath, sourceField, extraMonorepoStrategies, findMonorepoStartPath, } = options;
8
- const projects = await (0, monorepo_utils_1.getDependentProjects)(projectNameOrRootPath, {
9
- cwd: findMonorepoStartPath,
10
- recursive: true,
11
- filter: (0, monorepo_utils_1.filterByField)(sourceField),
12
- extraMonorepoStrategies,
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]
13
10
  });
14
- const includes = [];
15
- for (const project of projects) {
16
- includes.push(...project.getSourceEntryPaths({ field: sourceField }));
17
- }
18
- return includes;
11
+ }
12
+ _export(exports, {
13
+ pluginName: function() {
14
+ return pluginName;
15
+ },
16
+ getSourceInclude: function() {
17
+ return getSourceInclude;
18
+ },
19
+ builderPluginSourceBuild: function() {
20
+ return builderPluginSourceBuild;
21
+ }
22
+ });
23
+ const _monorepoutils = require("@modern-js/monorepo-utils");
24
+ const _utils = require("@modern-js/utils");
25
+ const log = (0, _utils.debug)("BUILDER_PLUGIN_SOURCE_BUILD");
26
+ const pluginName = "builder-plugin-source-build";
27
+ const getSourceInclude = async (options) => {
28
+ const { projectNameOrRootPath, sourceField, extraMonorepoStrategies, findMonorepoStartPath } = options;
29
+ const projects = await (0, _monorepoutils.getDependentProjects)(projectNameOrRootPath, {
30
+ cwd: findMonorepoStartPath,
31
+ recursive: true,
32
+ filter: (0, _monorepoutils.filterByField)(sourceField),
33
+ extraMonorepoStrategies
34
+ });
35
+ const includes = [];
36
+ for (const project of projects) {
37
+ includes.push(...project.getSourceEntryPaths({
38
+ field: sourceField
39
+ }));
40
+ }
41
+ log(`get include projects: ${includes}`);
42
+ return includes;
19
43
  };
20
- exports.getSourceInclude = getSourceInclude;
21
- const sourceBuildInWebpack = (api, options) => {
22
- const { sourceField, projectRootPath, projectName, extraMonorepoStrategies } = options;
23
- api.modifyBuilderConfig(async (config) => {
24
- var _a, _b, _c;
25
- const { sourceBuild = true } = (_a = config.experiments) !== null && _a !== void 0 ? _a : {};
26
- if (!sourceBuild) {
44
+ function builderPluginSourceBuild(options) {
45
+ const { projectName, sourceField = "source", extraMonorepoStrategies } = options !== null && options !== void 0 ? options : {};
46
+ return {
47
+ name: pluginName,
48
+ async setup(api) {
49
+ const projectRootPath = api.context.rootPath;
50
+ if (api.context.bundlerType === "webpack") {
51
+ api.modifyBuilderConfig(async (config) => {
52
+ var _config_experiments;
53
+ const { sourceBuild = true } = (_config_experiments = config.experiments) !== null && _config_experiments !== void 0 ? _config_experiments : {};
54
+ if (!sourceBuild) {
27
55
  return;
28
- }
29
- const includes = await (0, exports.getSourceInclude)({
56
+ }
57
+ const includes = await getSourceInclude({
30
58
  projectNameOrRootPath: projectName || projectRootPath,
31
59
  sourceField,
32
60
  findMonorepoStartPath: projectRootPath,
33
- extraMonorepoStrategies,
61
+ extraMonorepoStrategies
62
+ });
63
+ var _config_source;
64
+ config.source = (_config_source = config.source) !== null && _config_source !== void 0 ? _config_source : {};
65
+ var _config_source_include;
66
+ config.source.include = [
67
+ ...(_config_source_include = config.source.include) !== null && _config_source_include !== void 0 ? _config_source_include : [],
68
+ ...includes
69
+ ];
34
70
  });
35
- config.source = (_b = config.source) !== null && _b !== void 0 ? _b : {};
36
- config.source.include = [...((_c = config.source.include) !== null && _c !== void 0 ? _c : []), ...includes];
37
- });
38
- api.modifyBundlerChain(chain => {
39
- const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
40
- if (!sourceBuild) {
41
- return;
42
- }
43
- // Now not support chain.resolve.conditionNames API
44
- // chain.resolve.conditionNames.prepend(sourcePkgField);
45
- // when user not config source.resolveMainFields, mainFields is empty array
46
- if (chain.resolve.mainFields.values().length === 0) {
47
- // "..." is special syntax,it will retain the original value
48
- chain.resolve.mainFields.prepend('...');
49
- chain.resolve.mainFields.prepend(sourceField);
50
- }
51
- });
52
- api.modifyWebpackConfig(async (config) => {
53
- var _a, _b;
54
- const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
55
- if (!sourceBuild) {
71
+ api.modifyBundlerChain((chain, { CHAIN_ID }) => {
72
+ const { experiments: { sourceBuild }, tools: { tsLoader } } = api.getNormalizedConfig();
73
+ if (!sourceBuild) {
56
74
  return;
57
- }
58
- config.resolve = (_a = config.resolve) !== null && _a !== void 0 ? _a : {};
59
- config.resolve.conditionNames = [
60
- '...',
61
- sourceField,
62
- ...((_b = config.resolve.conditionNames) !== null && _b !== void 0 ? _b : []),
63
- ];
64
- });
65
- };
66
- exports.sourceBuildInWebpack = sourceBuildInWebpack;
67
- function builderPluginSourceBuild(options) {
68
- const { projectName, sourceField = 'source', extraMonorepoStrategies, } = options !== null && options !== void 0 ? options : {};
69
- return {
70
- name: exports.pluginName,
71
- async setup(api) {
72
- const projectRootPath = api.context.rootPath;
73
- // TODO: when rspack support tsconfig paths functionality, this comment will remove
74
- // if (api.context.bundlerType === 'rspack') {
75
- // (api as RspackBuilderPluginAPI).modifyRspackConfig(async config => {
76
- // // when support chain.resolve.conditionNames API, remove this logic
77
- // setConfig(config, 'resolve.conditionNames', [
78
- // '...', // Special syntax: retain the original value
79
- // sourceField,
80
- // ...(config.resolve?.conditionNames ?? []),
81
- // ]);
82
- // });
83
- // }
84
- if (api.context.bundlerType === 'webpack') {
85
- api.modifyBuilderConfig(async (config) => {
86
- var _a, _b, _c;
87
- const { sourceBuild = true } = (_a = config.experiments) !== null && _a !== void 0 ? _a : {};
88
- if (!sourceBuild) {
89
- return;
90
- }
91
- const includes = await (0, exports.getSourceInclude)({
92
- projectNameOrRootPath: projectName || projectRootPath,
93
- sourceField,
94
- findMonorepoStartPath: projectRootPath,
95
- extraMonorepoStrategies,
96
- });
97
- config.source = (_b = config.source) !== null && _b !== void 0 ? _b : {};
98
- config.source.include = [
99
- ...((_c = config.source.include) !== null && _c !== void 0 ? _c : []),
100
- ...includes,
101
- ];
102
- });
103
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
104
- const { experiments: { sourceBuild }, } = api.getNormalizedConfig();
105
- if (!sourceBuild) {
106
- return;
107
- }
108
- // webpack.js.org/configuration/module/#ruleresolve
109
- chain.module
110
- .rule(CHAIN_ID.RULE.JS)
111
- .resolve.mainFields.merge(['...', sourceField]);
112
- // webpack chain not support resolve.conditionNames
113
- chain.module.rule(CHAIN_ID.RULE.JS).resolve.merge({
114
- conditionNames: ['...', sourceField],
115
- });
116
- });
117
- }
118
- },
119
- };
75
+ }
76
+ const useTsLoader = Boolean(tsLoader);
77
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.mainFields.merge([
78
+ "...",
79
+ sourceField
80
+ ]);
81
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
82
+ conditionNames: [
83
+ "...",
84
+ sourceField
85
+ ]
86
+ });
87
+ });
88
+ }
89
+ }
90
+ };
120
91
  }
121
- exports.builderPluginSourceBuild = builderPluginSourceBuild;
@@ -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;