@modern-js/builder 2.19.1 → 2.21.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 +50 -0
- package/dist/plugins/checkSyntax.d.ts +2 -0
- package/dist/plugins/checkSyntax.js +59 -0
- package/dist/plugins/fileSize.d.ts +1 -1
- package/dist/plugins/fileSize.js +2 -2
- package/dist/plugins/html.js +9 -0
- package/dist/plugins/index.d.ts +2 -21
- package/dist/plugins/index.js +2 -0
- package/dist/plugins/tsChecker.d.ts +2 -0
- package/dist/plugins/tsChecker.js +96 -0
- package/package.json +6 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @modern-js/builder
|
|
2
2
|
|
|
3
|
+
## 2.21.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 863f8df: feat(rspack-provider): support security.checkSyntax in Rspack
|
|
8
|
+
|
|
9
|
+
feat(rspack-provider): 在使用 Rspack 构建时支持 security.checkSyntax 配置项
|
|
10
|
+
|
|
11
|
+
- 55d37e9: fix(builder): should not print file size of LICENSE.text
|
|
12
|
+
|
|
13
|
+
fix(builder): 打印文件体积时忽略 LICENSE.text
|
|
14
|
+
|
|
15
|
+
- 26dcf3a: chore: bump typescript to v5 in devDependencies
|
|
16
|
+
|
|
17
|
+
chore: 升级 devDependencies 中的 typescript 版本到 v5
|
|
18
|
+
|
|
19
|
+
- 441a579: feat(builder): support output.disableTsChecker in Rspack
|
|
20
|
+
|
|
21
|
+
feat(builder): 在使用 Rspack 构建时支持 output.disableTsChecker 配置项
|
|
22
|
+
|
|
23
|
+
- 43b4e83: feat: support security.nonce for add nonce attribute on script tag
|
|
24
|
+
feat: 支持 security.nonce 配置,为 script 标签添加 nonce 属性
|
|
25
|
+
- ad78387: chore(deps): bump babel-related dependencies to latest version
|
|
26
|
+
|
|
27
|
+
chore(deps): 升级 babel 相关依赖到最新版本
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [7d2972e]
|
|
30
|
+
- Updated dependencies [863f8df]
|
|
31
|
+
- Updated dependencies [e81eeaf]
|
|
32
|
+
- Updated dependencies [26dcf3a]
|
|
33
|
+
- Updated dependencies [1ef03dc]
|
|
34
|
+
- Updated dependencies [056627f]
|
|
35
|
+
- Updated dependencies [4274510]
|
|
36
|
+
- Updated dependencies [0fc15ca]
|
|
37
|
+
- Updated dependencies [43b4e83]
|
|
38
|
+
- Updated dependencies [ad78387]
|
|
39
|
+
- @modern-js/builder-shared@2.21.0
|
|
40
|
+
- @modern-js/utils@2.21.0
|
|
41
|
+
|
|
42
|
+
## 2.20.0
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 6b9d90a: chore: remove @babel/runtime. add @swc/helper and enable `externalHelper` config.
|
|
47
|
+
chore: 移除 @babel/runtime 依赖. 增加 @swc/helpers 依赖并且开启 `externalHelpers` 配置
|
|
48
|
+
- Updated dependencies [3c4e0a5]
|
|
49
|
+
- Updated dependencies [6b9d90a]
|
|
50
|
+
- @modern-js/builder-shared@2.20.0
|
|
51
|
+
- @modern-js/utils@2.20.0
|
|
52
|
+
|
|
3
53
|
## 2.19.1
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.builderPluginCheckSyntax = void 0;
|
|
27
|
+
const builder_shared_1 = require("@modern-js/builder-shared");
|
|
28
|
+
function builderPluginCheckSyntax() {
|
|
29
|
+
return {
|
|
30
|
+
name: 'builder-plugin-check-syntax',
|
|
31
|
+
setup(api) {
|
|
32
|
+
api.modifyBundlerChain(async (chain, { isProd, target }) => {
|
|
33
|
+
const config = api.getNormalizedConfig();
|
|
34
|
+
const { checkSyntax } = config.security;
|
|
35
|
+
if (!isProd ||
|
|
36
|
+
['node', 'web-worker'].includes(target) ||
|
|
37
|
+
!checkSyntax) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const targets = await getCheckTargets(api.context, config, target, checkSyntax);
|
|
41
|
+
const { CheckSyntaxPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
|
|
42
|
+
chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
|
|
43
|
+
{
|
|
44
|
+
targets,
|
|
45
|
+
exclude: typeof checkSyntax === 'object' ? checkSyntax.exclude : undefined,
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.builderPluginCheckSyntax = builderPluginCheckSyntax;
|
|
53
|
+
async function getCheckTargets(builderContext, builderConfig, builderTarget, checkSyntax) {
|
|
54
|
+
if (checkSyntax === true) {
|
|
55
|
+
const browserslist = await (0, builder_shared_1.getBrowserslistWithDefault)(builderContext.rootPath, builderConfig, builderTarget);
|
|
56
|
+
return browserslist || builder_shared_1.DEFAULT_BROWSERSLIST[builderTarget];
|
|
57
|
+
}
|
|
58
|
+
return checkSyntax.targets;
|
|
59
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { DefaultBuilderPlugin } from '@modern-js/builder-shared';
|
|
2
|
-
/** Filter source map files */
|
|
2
|
+
/** Filter source map and license files */
|
|
3
3
|
export declare const filterAsset: (asset: string) => boolean;
|
|
4
4
|
export declare const builderPluginFileSize: () => DefaultBuilderPlugin;
|
package/dist/plugins/fileSize.js
CHANGED
|
@@ -34,8 +34,8 @@ exports.builderPluginFileSize = exports.filterAsset = void 0;
|
|
|
34
34
|
const path_1 = __importDefault(require("path"));
|
|
35
35
|
const chalk_1 = __importDefault(require("@modern-js/utils/chalk"));
|
|
36
36
|
const builder_shared_1 = require("@modern-js/builder-shared");
|
|
37
|
-
/** Filter source map files */
|
|
38
|
-
const filterAsset = (asset) => !/\.map$/.test(asset);
|
|
37
|
+
/** Filter source map and license files */
|
|
38
|
+
const filterAsset = (asset) => !/\.map$/.test(asset) && !/\.LICENSE\.txt$/.test(asset);
|
|
39
39
|
exports.filterAsset = filterAsset;
|
|
40
40
|
const getAssetColor = (size) => {
|
|
41
41
|
if (size > 300 * 1000) {
|
package/dist/plugins/html.js
CHANGED
|
@@ -165,6 +165,15 @@ const builderPluginHtml = () => ({
|
|
|
165
165
|
.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`)
|
|
166
166
|
.use(HtmlPlugin, [finalOptions]);
|
|
167
167
|
}));
|
|
168
|
+
if (config.security) {
|
|
169
|
+
const { nonce } = config.security;
|
|
170
|
+
if (nonce) {
|
|
171
|
+
const { HtmlNoncePlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared')));
|
|
172
|
+
chain
|
|
173
|
+
.plugin(CHAIN_ID.PLUGIN.HTML_NONCE)
|
|
174
|
+
.use(HtmlNoncePlugin, [{ nonce, HtmlPlugin }]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
168
177
|
if (config.html) {
|
|
169
178
|
const { appIcon, crossorigin } = config.html;
|
|
170
179
|
if (crossorigin) {
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
cleanOutput: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
4
|
-
startUrl: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
5
|
-
fileSize: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
6
|
-
devtool: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
7
|
-
target: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
8
|
-
entry: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
9
|
-
cache: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
10
|
-
yaml: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
11
|
-
toml: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
12
|
-
svg: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
13
|
-
splitChunks: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
14
|
-
inlineChunk: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
15
|
-
bundleAnalyzer: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
16
|
-
font: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
17
|
-
image: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
18
|
-
media: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
19
|
-
assetsRetry: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
20
|
-
antd: () => Promise<import("@modern-js/builder-shared").DefaultBuilderPlugin>;
|
|
21
|
-
};
|
|
1
|
+
import { Plugins } from '@modern-js/builder-shared';
|
|
2
|
+
export declare const plugins: Plugins;
|
package/dist/plugins/index.js
CHANGED
|
@@ -45,4 +45,6 @@ exports.plugins = {
|
|
|
45
45
|
media: () => Promise.resolve().then(() => __importStar(require('./asset'))).then(m => m.builderAssetPlugin('media', builder_shared_1.MEDIA_EXTENSIONS)),
|
|
46
46
|
assetsRetry: () => Promise.resolve().then(() => __importStar(require('./assetsRetry'))).then(m => m.builderPluginAssetsRetry()),
|
|
47
47
|
antd: () => Promise.resolve().then(() => __importStar(require('./antd'))).then(m => m.builderAntdPlugin()),
|
|
48
|
+
tsChecker: () => Promise.resolve().then(() => __importStar(require('./tsChecker'))).then(m => m.builderPluginTsChecker()),
|
|
49
|
+
checkSyntax: () => Promise.resolve().then(() => __importStar(require('./checkSyntax'))).then(m => m.builderPluginCheckSyntax()),
|
|
48
50
|
};
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.builderPluginTsChecker = void 0;
|
|
27
|
+
const builderPluginTsChecker = () => {
|
|
28
|
+
return {
|
|
29
|
+
name: 'builder-plugin-ts-checker',
|
|
30
|
+
setup(api) {
|
|
31
|
+
api.modifyBundlerChain(async (chain, { target }) => {
|
|
32
|
+
const config = api.getNormalizedConfig();
|
|
33
|
+
// Use tsChecker if disableTsChecker is not `true`, So there are two situations for user:
|
|
34
|
+
// 1. tsLoader + transpileOnly + tsChecker
|
|
35
|
+
// 2. @babel/preset-typescript + tsChecker
|
|
36
|
+
if (config.output.disableTsChecker || !api.context.tsconfigPath) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// If there is multiple target, only apply tsChecker to the first target
|
|
40
|
+
// to avoid multiple tsChecker running at the same time
|
|
41
|
+
if (Array.isArray(api.context.target) &&
|
|
42
|
+
target !== api.context.target[0]) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { default: ForkTsCheckerWebpackPlugin } = await Promise.resolve().then(() => __importStar(require('@modern-js/builder-shared/fork-ts-checker-webpack-plugin')));
|
|
46
|
+
const { logger, CHAIN_ID, applyOptionsChain } = await Promise.resolve().then(() => __importStar(require('@modern-js/utils')));
|
|
47
|
+
// use typescript of user project
|
|
48
|
+
let typescriptPath;
|
|
49
|
+
try {
|
|
50
|
+
typescriptPath = require.resolve('typescript', {
|
|
51
|
+
paths: [api.context.rootPath],
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
logger.warn('"typescript" is not found in current project, Type Checker will not work.');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const tsCheckerOptions = applyOptionsChain({
|
|
59
|
+
typescript: {
|
|
60
|
+
// avoid OOM issue
|
|
61
|
+
memoryLimit: 8192,
|
|
62
|
+
// use tsconfig of user project
|
|
63
|
+
configFile: api.context.tsconfigPath,
|
|
64
|
+
typescriptPath,
|
|
65
|
+
},
|
|
66
|
+
issue: {
|
|
67
|
+
exclude: [
|
|
68
|
+
{ file: '**/*.(spec|test).ts' },
|
|
69
|
+
{ file: '**/node_modules/**/*' },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
logger: {
|
|
73
|
+
log() {
|
|
74
|
+
// do nothing
|
|
75
|
+
// we only want to display error messages
|
|
76
|
+
},
|
|
77
|
+
error(message) {
|
|
78
|
+
console.error(message.replace(/ERROR/g, 'Type Error'));
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
}, typeof config.tools.tsChecker === 'object'
|
|
82
|
+
? config.tools.tsChecker
|
|
83
|
+
: {});
|
|
84
|
+
if (api.context.bundlerType === 'rspack' &&
|
|
85
|
+
chain.get('mode') === 'production') {
|
|
86
|
+
logger.info('ts-checker running...');
|
|
87
|
+
logger.info('ts-checker is running slowly and will block builds until it is complete, please be patient and wait.');
|
|
88
|
+
}
|
|
89
|
+
chain
|
|
90
|
+
.plugin(CHAIN_ID.PLUGIN.TS_CHECKER)
|
|
91
|
+
.use(ForkTsCheckerWebpackPlugin, [tsCheckerOptions]);
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
exports.builderPluginTsChecker = builderPluginTsChecker;
|
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.21.0",
|
|
22
22
|
"jsnext:source": "./src/index.ts",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"main": "./dist/index.js",
|
|
@@ -31,16 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@svgr/webpack": "6.5.1",
|
|
34
|
-
"@modern-js/builder-shared": "2.
|
|
35
|
-
"@modern-js/utils": "2.
|
|
34
|
+
"@modern-js/builder-shared": "2.21.0",
|
|
35
|
+
"@modern-js/utils": "2.21.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@types/babel__core": "^7.1.19",
|
|
40
|
-
"@types/babel__preset-env": "^7.9.2",
|
|
38
|
+
"@types/babel__core": "^7.20.0",
|
|
41
39
|
"@types/node": "^14",
|
|
42
|
-
"typescript": "^
|
|
43
|
-
"@scripts/vitest-config": "2.
|
|
40
|
+
"typescript": "^5",
|
|
41
|
+
"@scripts/vitest-config": "2.21.0"
|
|
44
42
|
},
|
|
45
43
|
"publishConfig": {
|
|
46
44
|
"registry": "https://registry.npmjs.org/",
|