Skip to content

Commit 441a579

Browse files
9aoychenjiahan
andauthored
feat(builder): support output.disableTsChecker in rspack (#3751)
* feat: support output.disableTsChecker in rspack * docs: add changeset * Update packages/builder/builder/src/plugins/tsChecker.ts Co-authored-by: neverland <[email protected]> * fix: log & remove duplicate deps * fix: snapshot update --------- Co-authored-by: neverland <[email protected]>
1 parent fdb0406 commit 441a579

File tree

25 files changed

+653
-1469
lines changed

25 files changed

+653
-1469
lines changed

.changeset/neat-fans-think.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@modern-js/builder-rspack-provider': patch
3+
'@modern-js/builder': patch
4+
---
5+
6+
feat(builder): support output.disableTsChecker in Rspack
7+
8+
feat(builder): 在使用 Rspack 构建时支持 output.disableTsChecker 配置项

packages/builder/builder-rspack-provider/src/core/createCompiler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export async function createCompiler({
2626
timings: true,
2727
});
2828

29-
obj.children?.forEach(c => {
30-
c.time &&
31-
logger.success(`${c.name} compiled successfully in`, c.time, 'ms');
32-
});
29+
if (!stats.hasErrors()) {
30+
obj.children?.forEach(c => {
31+
c.time &&
32+
logger.success(`${c.name} compiled successfully in`, c.time, 'ms');
33+
});
34+
}
3335

3436
const { message, level } = await formatStats(stats);
3537

packages/builder/builder-rspack-provider/src/shared/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const applyDefaultPlugins = (plugins: Plugins) =>
2020
plugins.media(),
2121
plugins.svg(),
2222
plugins.html(),
23+
plugins.tsChecker(),
2324
// pug plugin should after html plugin
2425
import('../plugins/pug').then(m => m.builderPluginPug()),
2526
import('../plugins/babel').then(m => m.builderPluginBabel()),

packages/builder/builder-rspack-provider/tests/plugins/__snapshots__/default.test.ts.snap

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,29 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
650650
"publicPath": "/",
651651
},
652652
"plugins": [
653+
ForkTsCheckerWebpackPlugin {
654+
"options": {
655+
"issue": {
656+
"exclude": [
657+
{
658+
"file": "**/*.(spec|test).ts",
659+
},
660+
{
661+
"file": "**/node_modules/**/*",
662+
},
663+
],
664+
},
665+
"logger": {
666+
"error": [Function],
667+
"log": [Function],
668+
},
669+
"typescript": {
670+
"configFile": "<ROOT>/tsconfig.json",
671+
"memoryLimit": 8192,
672+
"typescriptPath": "<WORKSPACE>/node_modules/<PNPM_INNER>/typescript/lib/typescript.js",
673+
},
674+
},
675+
},
653676
RspackVirtualModulePlugin {},
654677
],
655678
"resolve": {
@@ -1326,6 +1349,29 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
13261349
"publicPath": "/",
13271350
},
13281351
"plugins": [
1352+
ForkTsCheckerWebpackPlugin {
1353+
"options": {
1354+
"issue": {
1355+
"exclude": [
1356+
{
1357+
"file": "**/*.(spec|test).ts",
1358+
},
1359+
{
1360+
"file": "**/node_modules/**/*",
1361+
},
1362+
],
1363+
},
1364+
"logger": {
1365+
"error": [Function],
1366+
"log": [Function],
1367+
},
1368+
"typescript": {
1369+
"configFile": "<ROOT>/tsconfig.json",
1370+
"memoryLimit": 8192,
1371+
"typescriptPath": "<WORKSPACE>/node_modules/<PNPM_INNER>/typescript/lib/typescript.js",
1372+
},
1373+
},
1374+
},
13291375
RspackVirtualModulePlugin {},
13301376
InlineChunkHtmlPlugin {
13311377
"distPath": {
@@ -1743,6 +1789,31 @@ exports[`applyDefaultPlugins > should apply default plugins correctyly when targ
17431789
"pathinfo": false,
17441790
"publicPath": "/",
17451791
},
1792+
"plugins": [
1793+
ForkTsCheckerWebpackPlugin {
1794+
"options": {
1795+
"issue": {
1796+
"exclude": [
1797+
{
1798+
"file": "**/*.(spec|test).ts",
1799+
},
1800+
{
1801+
"file": "**/node_modules/**/*",
1802+
},
1803+
],
1804+
},
1805+
"logger": {
1806+
"error": [Function],
1807+
"log": [Function],
1808+
},
1809+
"typescript": {
1810+
"configFile": "<ROOT>/tsconfig.json",
1811+
"memoryLimit": 8192,
1812+
"typescriptPath": "<WORKSPACE>/node_modules/<PNPM_INNER>/typescript/lib/typescript.js",
1813+
},
1814+
},
1815+
},
1816+
],
17461817
"resolve": {
17471818
"conditionNames": [
17481819
"require",
@@ -2423,6 +2494,29 @@ exports[`tools.rspack > should match snapshot 1`] = `
24232494
TestPlugin {
24242495
"name": "TestPlugin",
24252496
},
2497+
ForkTsCheckerWebpackPlugin {
2498+
"options": {
2499+
"issue": {
2500+
"exclude": [
2501+
{
2502+
"file": "**/*.(spec|test).ts",
2503+
},
2504+
{
2505+
"file": "**/node_modules/**/*",
2506+
},
2507+
],
2508+
},
2509+
"logger": {
2510+
"error": [Function],
2511+
"log": [Function],
2512+
},
2513+
"typescript": {
2514+
"configFile": "<ROOT>/tsconfig.json",
2515+
"memoryLimit": 8192,
2516+
"typescriptPath": "<WORKSPACE>/node_modules/<PNPM_INNER>/typescript/lib/typescript.js",
2517+
},
2518+
},
2519+
},
24262520
RspackVirtualModulePlugin {},
24272521
],
24282522
"resolve": {

packages/builder/builder-shared/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
"jsnext:source": "./src/index.ts",
3838
"default": "./dist/index.js"
3939
},
40+
"./fork-ts-checker-webpack-plugin": {
41+
"jsnext:source": "./src/exports/fork-ts-checker-webpack-plugin.ts",
42+
"default": "./dist/exports/fork-ts-checker-webpack-plugin.js"
43+
},
4044
"./open": {
4145
"types": "./compiled/open/index.d.ts",
4246
"default": "./compiled/open/index.js"
@@ -70,6 +74,9 @@
7074
"open": [
7175
"./compiled/open/index.d.ts"
7276
],
77+
"fork-ts-checker-webpack-plugin": [
78+
"./dist/exports/fork-ts-checker-webpack-plugin.d.ts"
79+
],
7380
"webpack-bundle-analyzer": [
7481
"./compiled/webpack-bundle-analyzer/index.d.ts"
7582
],
@@ -96,6 +103,7 @@
96103
"@modern-js/types": "workspace:*",
97104
"@modern-js/utils": "workspace:*",
98105
"@babel/core": "^7.21.8",
106+
"fork-ts-checker-webpack-plugin": "8.0.0",
99107
"acorn": "^8.8.1",
100108
"caniuse-lite": "^1.0.30001451",
101109
"cheerio": "1.0.0-rc.12",
@@ -127,6 +135,7 @@
127135
"./webpack-5-chain": "./compiled/webpack-5-chain/index.js",
128136
"./test-stub": "./dist/test-stub/index.js",
129137
"./zod": "./dist/exports/zod.js",
138+
"./fork-ts-checker-webpack-plugin": "./dist/exports/fork-ts-checker-webpack-plugin.js",
130139
"./pug": "./compiled/pug/index.js"
131140
}
132141
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
2+
3+
export default ForkTsCheckerWebpackPlugin;

packages/builder/builder-shared/src/test-stub/helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ export const mockBuilderPlugins: Plugins = {
2929
svg: genMockPlugin('builder-plugin-svg'),
3030
html: genMockPlugin('builder-plugin-html'),
3131
antd: genMockPlugin('antd'),
32+
tsChecker: genMockPlugin('builder-plugin-ts-checker'),
3233
checkSyntax: genMockPlugin('builder-plugin-check-syntax'),
3334
};

packages/builder/builder-shared/src/types/bundlerConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export interface BundlerChain
157157
| 'externalsType'
158158
| 'externalsPresets'
159159
| 'entry'
160+
| 'get'
160161
> {
161162
toConfig: () => BundlerConfig;
162163
optimization: PickAndModifyThis<

packages/builder/builder-shared/src/types/config/tools.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
SassLoaderOptions,
1010
LessLoaderOptions,
1111
PugOptions,
12+
ForkTSCheckerOptions,
1213
} from '../thirdParty';
1314
import { BundlerChain } from '../bundlerConfig';
1415
import { ModifyChainUtils } from '../hooks';
@@ -41,6 +42,8 @@ export type ToolsBabelConfig = ChainedConfig<
4142

4243
export type ToolsPugConfig = true | ChainedConfig<PugOptions>;
4344

45+
export type ToolsTSCheckerConfig = ChainedConfig<ForkTSCheckerOptions>;
46+
4447
export interface SharedToolsConfig {
4548
/**
4649
* Configure bundler config base on [webpack-chain](https://github.com/neutrinojs/webpack-chain)
@@ -71,4 +74,8 @@ export interface SharedToolsConfig {
7174
* Configure the [Pug](https://pugjs.org/) template engine.
7275
*/
7376
pug?: ToolsPugConfig;
77+
/**
78+
* Modify the options of [fork-ts-checker-webpack-plugin](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin).
79+
*/
80+
tsChecker?: ToolsTSCheckerConfig;
7481
}

packages/builder/builder-shared/src/types/plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type Plugins = {
5252
svg: PluginsFn;
5353
html: PluginsFn;
5454
antd: PluginsFn;
55+
tsChecker: PluginsFn;
5556
checkSyntax: PluginsFn;
5657
};
5758

0 commit comments

Comments
 (0)