Skip to content

Commit 7d2972e

Browse files
authored
feat(builder): update rspack to 0.1.12 (#3741)
* fix: output.copy not work in rspack * docs: add output.copy changeset * fix: update rspack * docs: add rspack changeset
1 parent 76a3c51 commit 7d2972e

File tree

13 files changed

+214
-580
lines changed

13 files changed

+214
-580
lines changed

.changeset/cold-poets-drum.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modern-js/builder-rspack-provider': patch
3+
---
4+
5+
fix(builder): output.copy not work in Rspack
6+
7+
fix(builder): output.copy 在 Rspack 构建时不生效

.changeset/dull-geckos-walk.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-shared': patch
4+
---
5+
6+
feat(builder): update rspack to 0.1.12
7+
8+
feat(builder): 升级 rspack 到 0.1.12 版本

packages/builder/builder-rspack-provider/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
"@modern-js/types": "workspace:*",
5757
"@modern-js/utils": "workspace:*",
5858
"@babel/preset-typescript": "^7.21.5",
59-
"@rspack/core": "0.0.0-canary-22b006c-20230517164249",
60-
"@rspack/dev-client": "0.0.0-canary-22b006c-20230517164249",
61-
"@rspack/dev-middleware": "0.0.0-canary-22b006c-20230517164249",
62-
"@rspack/plugin-html": "0.0.0-canary-22b006c-20230517164249",
63-
"@rspack/postcss-loader": "0.0.0-canary-22b006c-20230517164249",
59+
"@rspack/core": "0.1.12",
60+
"@rspack/dev-client": "0.1.12",
61+
"@rspack/dev-middleware": "0.1.12",
62+
"@rspack/plugin-html": "0.1.12",
63+
"@rspack/postcss-loader": "0.1.12",
6464
"rspack-manifest-plugin": "5.0.0-alpha0",
6565
"caniuse-lite": "^1.0.30001451",
6666
"core-js": "~3.30.0",

packages/builder/builder-rspack-provider/src/plugins/output.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ export const builderPluginOutput = (): BuilderPlugin => ({
3131
}
3232

3333
if (config.output.copy) {
34-
setConfig(rspackConfig, 'builtins.copy', config.output.copy);
34+
const { copy } = config.output;
35+
const options = Array.isArray(copy) ? { patterns: copy } : copy;
36+
37+
setConfig(rspackConfig, 'builtins.copy', {
38+
...options,
39+
patterns: [
40+
...(rspackConfig?.builtins?.copy?.patterns || []),
41+
...options.patterns,
42+
],
43+
});
3544
}
3645
});
3746
},

packages/builder/builder-rspack-provider/src/types/config/output.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type OutputConfig = SharedOutputConfig & {
99
/**
1010
* Copies the specified file or directory to the dist directory.
1111
*/
12-
copy?: Builtins['copy'];
12+
copy?: Builtins['copy'] | NonNullable<Builtins['copy']>['patterns'];
1313
/**
1414
* Convert px to rem in CSS.
1515
*/

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ exports[`plugins/output > should allow to use copy plugin 1`] = `
5858
}
5959
`;
6060

61+
exports[`plugins/output > should allow to use copy plugin with multiply config 1`] = `
62+
{
63+
"builtins": {
64+
"copy": {
65+
"patterns": [
66+
{
67+
"from": "test",
68+
},
69+
"src/assets/",
70+
"tests/",
71+
],
72+
},
73+
},
74+
"module": {},
75+
"output": {
76+
"chunkFilename": "static/js/async/[name].js",
77+
"cssChunkFilename": "static/css/async/[name].css",
78+
"cssFilename": "static/css/[name].css",
79+
"filename": "static/js/[name].js",
80+
"hashFunction": "xxhash64",
81+
"path": "<ROOT>/dist",
82+
"pathinfo": false,
83+
"publicPath": "/",
84+
},
85+
}
86+
`;
87+
6188
exports[`plugins/output > should allow to use filename.js to modify filename 1`] = `
6289
{
6390
"module": {},

packages/builder/builder-rspack-provider/tests/plugins/output.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,34 @@ describe('plugins/output', () => {
9292
} = await builder.inspectConfig();
9393
expect(bundlerConfigs[0]).toMatchSnapshot();
9494
});
95+
96+
it('should allow to use copy plugin with multiply config', async () => {
97+
const builder = await createBuilder({
98+
plugins: [builderPluginOutput()],
99+
builderConfig: {
100+
output: {
101+
copy: [
102+
{
103+
from: 'test',
104+
},
105+
'src/assets/',
106+
],
107+
},
108+
tools: {
109+
rspack: {
110+
builtins: {
111+
copy: {
112+
patterns: ['tests/'],
113+
},
114+
},
115+
},
116+
},
117+
},
118+
});
119+
120+
const {
121+
origin: { bundlerConfigs },
122+
} = await builder.inspectConfig();
123+
expect(bundlerConfigs[0]).toMatchSnapshot();
124+
});
95125
});

packages/builder/builder-shared/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@
108108
"html-webpack-plugin": "5.5.0",
109109
"terser": "^5.14.1",
110110
"typescript": "^5",
111-
"webpack": "^5.82.1",
112-
"@rspack/core": "0.0.0-canary-22b006c-20230517164249"
111+
"webpack": "^5.82.1"
113112
},
114113
"publishConfig": {
115114
"registry": "https://registry.npmjs.org/",

packages/builder/builder-shared/src/devServer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
BuilderContext,
66
OnAfterStartDevServerFn,
77
OnBeforeStartDevServerFn,
8+
CompilerTapFn,
89
} from './types';
910
import type { ModernDevServerOptions, Server } from '@modern-js/server';
1011
import { merge } from '@modern-js/utils/lodash';
@@ -207,10 +208,6 @@ type ServerCallbacks = {
207208
onDone: (stats: any) => void;
208209
};
209210

210-
type CompilerTapFn<CallBack extends (...args: any[]) => void> = {
211-
tap: (name: string, cb: CallBack) => void;
212-
};
213-
214211
export const setupServerHooks = (
215212
compiler: {
216213
name?: Compiler['name'];

packages/builder/builder-shared/src/patch.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import path from 'path';
22
import { pathToFileURL } from 'url';
3-
import type {
4-
Compiler as WebpackCompiler,
5-
MultiCompiler as WebpackMultiCompiler,
6-
} from 'webpack';
7-
import type {
8-
Compiler as RspackCompiler,
9-
MultiCompiler as RspackMultiCompiler,
10-
} from '@rspack/core';
3+
import { CompilerTapFn } from './types';
114

125
const GLOBAL_PATCHED_SYMBOL: unique symbol = Symbol('GLOBAL_PATCHED_SYMBOL');
136

@@ -33,13 +26,14 @@ export function unpatchGlobalLocation() {
3326
}
3427
}
3528

36-
export function patchCompilerGlobalLocation(
37-
compiler:
38-
| WebpackCompiler
39-
| RspackCompiler
40-
| WebpackMultiCompiler
41-
| RspackMultiCompiler,
42-
) {
29+
export function patchCompilerGlobalLocation(compiler: {
30+
hooks: {
31+
run: CompilerTapFn;
32+
watchRun: CompilerTapFn;
33+
watchClose: CompilerTapFn;
34+
done: CompilerTapFn;
35+
};
36+
}) {
4337
// https://github.com/webpack/webpack/blob/136b723023f8f26d71eabdd16badf04c1c8554e4/lib/MultiCompiler.js#L64
4438
compiler.hooks.run.tap('PatchGlobalLocation', patchGlobalLocation);
4539
compiler.hooks.watchRun.tap('PatchGlobalLocation', patchGlobalLocation);

0 commit comments

Comments
 (0)