@modern-js/builder 2.26.0 → 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.
- package/CHANGELOG.md +19 -0
- package/dist/createBuilder.d.ts +1 -1
- package/dist/createBuilder.js +48 -38
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -8
- package/dist/plugins/antd.d.ts +1 -1
- package/dist/plugins/antd.js +52 -30
- package/dist/plugins/arco.d.ts +1 -1
- package/dist/plugins/arco.js +43 -35
- package/dist/plugins/asset.d.ts +1 -1
- package/dist/plugins/asset.js +29 -25
- package/dist/plugins/assetsRetry.d.ts +1 -1
- package/dist/plugins/assetsRetry.js +34 -51
- package/dist/plugins/bundleAnalyzer.d.ts +1 -1
- package/dist/plugins/bundleAnalyzer.js +29 -50
- package/dist/plugins/cache.d.ts +1 -1
- package/dist/plugins/cache.js +68 -87
- package/dist/plugins/checkSyntax.d.ts +1 -1
- package/dist/plugins/checkSyntax.js +40 -54
- package/dist/plugins/cleanOutput.d.ts +1 -1
- package/dist/plugins/cleanOutput.js +22 -38
- package/dist/plugins/devtool.d.ts +1 -1
- package/dist/plugins/devtool.js +23 -21
- package/dist/plugins/entry.d.ts +1 -1
- package/dist/plugins/entry.js +23 -19
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +28 -25
- package/dist/plugins/fileSize.d.ts +1 -1
- package/dist/plugins/fileSize.js +124 -130
- package/dist/plugins/html.d.ts +1 -1
- package/dist/plugins/html.js +203 -206
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +40 -53
- package/dist/plugins/inlineChunk.d.ts +1 -1
- package/dist/plugins/inlineChunk.js +50 -59
- package/dist/plugins/moment.d.ts +1 -1
- package/dist/plugins/moment.js +23 -20
- package/dist/plugins/rem.d.ts +1 -1
- package/dist/plugins/rem.js +74 -97
- package/dist/plugins/sourceBuild.d.ts +12 -12
- package/dist/plugins/sourceBuild.js +125 -109
- package/dist/plugins/splitChunks.d.ts +1 -1
- package/dist/plugins/splitChunks.js +206 -229
- package/dist/plugins/startUrl.d.ts +1 -1
- package/dist/plugins/startUrl.js +62 -78
- package/dist/plugins/svg.d.ts +1 -1
- package/dist/plugins/svg.js +64 -81
- package/dist/plugins/target.d.ts +1 -1
- package/dist/plugins/target.js +52 -31
- package/dist/plugins/toml.d.ts +1 -1
- package/dist/plugins/toml.js +16 -15
- package/dist/plugins/tsChecker.d.ts +1 -1
- package/dist/plugins/tsChecker.js +69 -92
- package/dist/plugins/wasm.d.ts +1 -1
- package/dist/plugins/wasm.js +31 -32
- package/dist/plugins/yaml.d.ts +1 -1
- package/dist/plugins/yaml.js +16 -15
- package/package.json +11 -9
|
@@ -1,63 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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;
|
package/dist/plugins/moment.d.ts
CHANGED
|
@@ -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;
|
package/dist/plugins/moment.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
package/dist/plugins/rem.d.ts
CHANGED
|
@@ -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;
|
package/dist/plugins/rem.js
CHANGED
|
@@ -1,106 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
|
|
16
|
+
enableRuntime: true,
|
|
17
|
+
rootFontSize: 50
|
|
35
18
|
};
|
|
36
|
-
const builderPluginRem = () =>
|
|
37
|
-
|
|
19
|
+
const builderPluginRem = () => {
|
|
20
|
+
return {
|
|
21
|
+
name: "builder-plugin-rem",
|
|
38
22
|
pre: [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
"builder-plugin-css",
|
|
24
|
+
"builder-plugin-less",
|
|
25
|
+
"builder-plugin-sass",
|
|
26
|
+
"builder-plugin-stylus"
|
|
43
27
|
],
|
|
44
28
|
setup(api) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
};
|
|
@@ -4,20 +4,20 @@ 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
projectNameOrRootPath: string;
|
|
8
|
+
findMonorepoStartPath: string;
|
|
9
|
+
sourceField: string;
|
|
10
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
11
11
|
}) => Promise<string[]>;
|
|
12
12
|
export declare const sourceBuildInWebpack: (api: WebpackBuilderPluginAPI, options: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
sourceField: string;
|
|
14
|
+
projectRootPath: string;
|
|
15
|
+
projectName?: string;
|
|
16
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
17
17
|
}) => void;
|
|
18
18
|
export interface PluginSourceBuildOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
projectName?: string;
|
|
20
|
+
sourceField?: string;
|
|
21
|
+
extraMonorepoStrategies?: ExtraMonorepoStrategies;
|
|
22
22
|
}
|
|
23
|
-
export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
|
|
23
|
+
export declare function builderPluginSourceBuild(options?: PluginSourceBuildOptions): BuilderPlugin<WebpackBuilderPluginAPI | RspackBuilderPluginAPI>;
|
|
@@ -1,121 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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";
|
|
6
28
|
const getSourceInclude = async (options) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
13
57
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
70
|
}
|
|
18
|
-
|
|
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
|
+
});
|
|
19
90
|
};
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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) {
|
|
27
102
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
103
|
+
}
|
|
104
|
+
const includes = await getSourceInclude({
|
|
30
105
|
projectNameOrRootPath: projectName || projectRootPath,
|
|
31
106
|
sourceField,
|
|
32
107
|
findMonorepoStartPath: projectRootPath,
|
|
33
|
-
extraMonorepoStrategies
|
|
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
|
+
];
|
|
34
117
|
});
|
|
35
|
-
|
|
36
|
-
|
|
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) {
|
|
118
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
|
119
|
+
const { experiments: { sourceBuild } } = api.getNormalizedConfig();
|
|
120
|
+
if (!sourceBuild) {
|
|
56
121
|
return;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
};
|
|
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
|
+
};
|
|
120
137
|
}
|
|
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;
|