@modern-js/builder 2.22.0 → 2.23.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 +62 -0
- package/dist/createBuilder.js +2 -1
- package/dist/plugins/assetsRetry.js +6 -1
- package/dist/plugins/html.js +5 -3
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/rem.d.ts +2 -0
- package/dist/plugins/rem.js +106 -0
- package/dist/plugins/splitChunks.js +15 -2
- package/dist/plugins/startUrl.js +2 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# @modern-js/builder
|
|
2
2
|
|
|
3
|
+
## 2.23.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9b270b6: feat(builder): extend rules of splitByExperience
|
|
8
|
+
feat(builder): 拓展 splitByExperience 内部规则
|
|
9
|
+
- 7e6fb5f: chore: publishConfig add provenance config
|
|
10
|
+
|
|
11
|
+
chore: publishConfig 增加 provenance 配置
|
|
12
|
+
|
|
13
|
+
- 692cc0e: fix(builder): assetsRetry.crossOrigin default to html.crossorigin
|
|
14
|
+
|
|
15
|
+
fix(builder): assetsRetry.crossOrigin 默认值与 html.crossorigin 保持一致
|
|
16
|
+
|
|
17
|
+
- a82d6f7: fix(builder): single-vendor chunkSplit not work as expected
|
|
18
|
+
|
|
19
|
+
fix(builder): single-vendor 拆包规则未按照预期生效
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [15eac36]
|
|
22
|
+
- Updated dependencies [d4e85c1]
|
|
23
|
+
- Updated dependencies [7e6fb5f]
|
|
24
|
+
- Updated dependencies [a7a7ad7]
|
|
25
|
+
- Updated dependencies [6dec7c2]
|
|
26
|
+
- Updated dependencies [c3216b5]
|
|
27
|
+
- Updated dependencies [f14f920]
|
|
28
|
+
- Updated dependencies [692cc0e]
|
|
29
|
+
- Updated dependencies [38eccef]
|
|
30
|
+
- Updated dependencies [f91c557]
|
|
31
|
+
- Updated dependencies [a82d6f7]
|
|
32
|
+
- @modern-js/builder-shared@2.23.0
|
|
33
|
+
- @modern-js/utils@2.23.0
|
|
34
|
+
|
|
35
|
+
## 2.22.1
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- a470c04: chore(builder): reuse rem plugin between rspack and webpack provider
|
|
40
|
+
|
|
41
|
+
chore(builder): 在 rspack 和 webpack provider 间复用 rem 插件
|
|
42
|
+
|
|
43
|
+
- bd4b150: feat(builder): add builder.serve method
|
|
44
|
+
|
|
45
|
+
feat(builder): 新增 builder.serve 方法
|
|
46
|
+
|
|
47
|
+
- d4045ed: fix(builder): print https URLs when devServer.https is true
|
|
48
|
+
|
|
49
|
+
fix(builder): 当 devServer.https 为 true 时,输出 https 的 URLs
|
|
50
|
+
|
|
51
|
+
- Updated dependencies [e2848a2]
|
|
52
|
+
- Updated dependencies [a470c04]
|
|
53
|
+
- Updated dependencies [95ffa6b]
|
|
54
|
+
- Updated dependencies [12d54ae]
|
|
55
|
+
- Updated dependencies [bd4b150]
|
|
56
|
+
- Updated dependencies [dd36311]
|
|
57
|
+
- Updated dependencies [d4045ed]
|
|
58
|
+
- Updated dependencies [8bd9981]
|
|
59
|
+
- Updated dependencies [1f02cd2]
|
|
60
|
+
- Updated dependencies [cfcf003]
|
|
61
|
+
- Updated dependencies [15181be]
|
|
62
|
+
- @modern-js/utils@2.22.1
|
|
63
|
+
- @modern-js/builder-shared@2.22.1
|
|
64
|
+
|
|
3
65
|
## 2.22.0
|
|
4
66
|
|
|
5
67
|
### Patch Changes
|
package/dist/createBuilder.js
CHANGED
|
@@ -6,7 +6,7 @@ const plugins_1 = require("./plugins");
|
|
|
6
6
|
async function createBuilder(provider, options) {
|
|
7
7
|
const builderOptions = (0, builder_shared_1.applyDefaultBuilderOptions)(options);
|
|
8
8
|
const pluginStore = (0, builder_shared_1.createPluginStore)();
|
|
9
|
-
const { build, pluginAPI, publicContext, initConfigs, inspectConfig, createCompiler, startDevServer, applyDefaultPlugins, } = await provider({
|
|
9
|
+
const { build, serve, pluginAPI, publicContext, initConfigs, inspectConfig, createCompiler, startDevServer, applyDefaultPlugins, } = await provider({
|
|
10
10
|
pluginStore,
|
|
11
11
|
builderOptions,
|
|
12
12
|
plugins: plugins_1.plugins,
|
|
@@ -29,6 +29,7 @@ async function createBuilder(provider, options) {
|
|
|
29
29
|
'getBuilderConfig',
|
|
30
30
|
'getNormalizedConfig',
|
|
31
31
|
]),
|
|
32
|
+
serve,
|
|
32
33
|
build,
|
|
33
34
|
createCompiler,
|
|
34
35
|
initConfigs,
|
|
@@ -36,9 +36,14 @@ function builderPluginAssetsRetry() {
|
|
|
36
36
|
}
|
|
37
37
|
const { AssetsRetryPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
|
|
38
38
|
const distDir = (0, builder_shared_1.getDistPath)(config.output, 'js');
|
|
39
|
+
const { assetsRetry = {} } = config.output;
|
|
40
|
+
// assetsRetry.crossOrigin should be same as html.crossorigin by default
|
|
41
|
+
if (assetsRetry.crossOrigin === undefined) {
|
|
42
|
+
assetsRetry.crossOrigin = config.html.crossorigin;
|
|
43
|
+
}
|
|
39
44
|
chain.plugin(CHAIN_ID.PLUGIN.ASSETS_RETRY).use(AssetsRetryPlugin, [
|
|
40
45
|
{
|
|
41
|
-
...
|
|
46
|
+
...assetsRetry,
|
|
42
47
|
distDir,
|
|
43
48
|
HtmlPlugin,
|
|
44
49
|
},
|
package/dist/plugins/html.js
CHANGED
|
@@ -206,15 +206,17 @@ const builderPluginHtml = () => ({
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
});
|
|
209
|
-
|
|
209
|
+
const emitRouteJson = async () => {
|
|
210
210
|
const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
|
|
211
211
|
const routeFilePath = path_1.default.join(api.context.distPath, ROUTE_SPEC_FILE);
|
|
212
|
-
// generate a basic route.json for modern.js
|
|
212
|
+
// generate a basic route.json for modern.js server
|
|
213
213
|
// if the framework has already generate a route.json, do nothing
|
|
214
214
|
if (!(await (0, builder_shared_1.isFileExists)(routeFilePath)) && routesInfo.length) {
|
|
215
215
|
await fs.outputFile(routeFilePath, JSON.stringify({ routes: routesInfo }, null, 2));
|
|
216
216
|
}
|
|
217
|
-
}
|
|
217
|
+
};
|
|
218
|
+
api.onBeforeBuild(emitRouteJson);
|
|
219
|
+
api.onBeforeStartDevServer(emitRouteJson);
|
|
218
220
|
(0, exports.applyInjectTags)(api);
|
|
219
221
|
},
|
|
220
222
|
});
|
package/dist/plugins/index.js
CHANGED
|
@@ -48,4 +48,5 @@ exports.plugins = {
|
|
|
48
48
|
arco: () => Promise.resolve().then(() => __importStar(require('./arco'))).then(m => m.builderPluginArco()),
|
|
49
49
|
tsChecker: () => Promise.resolve().then(() => __importStar(require('./tsChecker'))).then(m => m.builderPluginTsChecker()),
|
|
50
50
|
checkSyntax: () => Promise.resolve().then(() => __importStar(require('./checkSyntax'))).then(m => m.builderPluginCheckSyntax()),
|
|
51
|
+
rem: () => Promise.resolve().then(() => __importStar(require('./rem'))).then(m => m.builderPluginRem()),
|
|
51
52
|
};
|
|
@@ -0,0 +1,106 @@
|
|
|
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;
|
|
17
|
+
});
|
|
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");
|
|
32
|
+
const defaultOptions = {
|
|
33
|
+
enableRuntime: true,
|
|
34
|
+
rootFontSize: 50,
|
|
35
|
+
};
|
|
36
|
+
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;
|
|
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
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
exports.builderPluginRem = builderPluginRem;
|
|
@@ -61,6 +61,7 @@ async function splitByExperience(ctx) {
|
|
|
61
61
|
react: (0, exports.createDependenciesRegExp)('react', 'react-dom'),
|
|
62
62
|
router: (0, exports.createDependenciesRegExp)('react-router', 'react-router-dom', '@remix-run/router', 'history'),
|
|
63
63
|
lodash: (0, exports.createDependenciesRegExp)('lodash', 'lodash-es'),
|
|
64
|
+
axios: (0, exports.createDependenciesRegExp)('axios', /axios-.+/),
|
|
64
65
|
};
|
|
65
66
|
// Detect if the package is installed in current project
|
|
66
67
|
// If installed, add the package to cache group
|
|
@@ -113,7 +114,7 @@ function splitByModule(ctx) {
|
|
|
113
114
|
// Core group
|
|
114
115
|
vendors: {
|
|
115
116
|
priority: -10,
|
|
116
|
-
test:
|
|
117
|
+
test: builder_shared_1.NODE_MODULES_REGEX,
|
|
117
118
|
// todo: not support in rspack
|
|
118
119
|
name(module) {
|
|
119
120
|
return (0, builder_shared_1.getPackageNameFromModulePath)(module.context);
|
|
@@ -161,14 +162,26 @@ function allInOne(_ctx) {
|
|
|
161
162
|
}
|
|
162
163
|
// Ignore user defined cache group to get single vendor chunk.
|
|
163
164
|
function singleVendor(ctx) {
|
|
164
|
-
const { override, defaultConfig } = ctx;
|
|
165
|
+
const { override, defaultConfig, userDefinedCacheGroups } = ctx;
|
|
165
166
|
(0, assert_1.default)(defaultConfig !== false);
|
|
166
167
|
(0, assert_1.default)(override !== false);
|
|
168
|
+
const singleVendorCacheGroup = {
|
|
169
|
+
singleVendor: {
|
|
170
|
+
test: builder_shared_1.NODE_MODULES_REGEX,
|
|
171
|
+
priority: 0,
|
|
172
|
+
chunks: 'all',
|
|
173
|
+
name: 'vendor',
|
|
174
|
+
enforce: true,
|
|
175
|
+
reuseExistingChunk: true,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
167
178
|
return {
|
|
168
179
|
...defaultConfig,
|
|
169
180
|
...override,
|
|
170
181
|
cacheGroups: {
|
|
171
182
|
...defaultConfig.cacheGroups,
|
|
183
|
+
...singleVendorCacheGroup,
|
|
184
|
+
...userDefinedCacheGroups,
|
|
172
185
|
...override.cacheGroups,
|
|
173
186
|
},
|
|
174
187
|
};
|
package/dist/plugins/startUrl.js
CHANGED
|
@@ -44,7 +44,8 @@ function builderPluginStartUrl() {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const config = api.getNormalizedConfig();
|
|
47
|
-
const {
|
|
47
|
+
const { startUrl, beforeStartUrl } = config.dev;
|
|
48
|
+
const { https } = api.context.devServer || {};
|
|
48
49
|
if (!startUrl) {
|
|
49
50
|
return;
|
|
50
51
|
}
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=14.0.0"
|
|
20
20
|
},
|
|
21
|
-
"version": "2.
|
|
21
|
+
"version": "2.23.0",
|
|
22
22
|
"jsnext:source": "./src/index.ts",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"main": "./dist/index.js",
|
|
@@ -31,18 +31,19 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@svgr/webpack": "8.0.1",
|
|
34
|
-
"@modern-js/builder-shared": "2.
|
|
35
|
-
"@modern-js/utils": "2.
|
|
34
|
+
"@modern-js/builder-shared": "2.23.0",
|
|
35
|
+
"@modern-js/utils": "2.23.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/babel__core": "^7.20.0",
|
|
39
39
|
"@types/node": "^14",
|
|
40
40
|
"typescript": "^5",
|
|
41
|
-
"@scripts/vitest-config": "2.
|
|
41
|
+
"@scripts/vitest-config": "2.23.0"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"registry": "https://registry.npmjs.org/",
|
|
45
|
-
"access": "public"
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"new": "modern new",
|