Skip to content

Commit 57c6341

Browse files
authored
chore(core): use Rslib to bundle client code (#3938)
1 parent 56fe16e commit 57c6341

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

packages/core/modern.config.ts

-20
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,6 @@ export default defineConfig({
109109
return options;
110110
},
111111
},
112-
// Client / ESM
113-
{
114-
format: 'esm',
115-
input: {
116-
hmr: 'src/client/hmr.ts',
117-
overlay: 'src/client/overlay.ts',
118-
},
119-
target: BUILD_TARGET.client,
120-
dts: false,
121-
externals: ['./hmr'],
122-
outDir: './dist/client',
123-
autoExtension: true,
124-
externalHelpers: true,
125-
// Skip esbuild transform and only use SWC to transform,
126-
// because esbuild will transform `import.meta`.
127-
esbuildOptions: (options) => {
128-
options.target = undefined;
129-
return options;
130-
},
131-
},
132112
// Types
133113
{
134114
externals,

packages/core/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"types.d.ts"
4747
],
4848
"scripts": {
49-
"build": "modern build && tsc-alias -p tsconfig.json",
49+
"build": "modern build && rslib build && tsc-alias -p tsconfig.json",
50+
"build:rslib": "rslib build",
5051
"dev": "modern build --watch",
5152
"prebundle": "prebundle"
5253
},
@@ -58,6 +59,7 @@
5859
},
5960
"devDependencies": {
6061
"@modern-js/module-tools": "^2.61.0",
62+
"@rslib/core": "0.0.16",
6163
"@types/connect": "3.4.38",
6264
"@types/fs-extra": "^11.0.4",
6365
"@types/node": "18.x",

packages/core/rslib.config.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { defineConfig } from '@rslib/core';
2+
3+
export default defineConfig({
4+
lib: [
5+
// Client / ESM
6+
{
7+
format: 'esm',
8+
syntax: 'es2017',
9+
source: {
10+
entry: {
11+
hmr: 'src/client/hmr.ts',
12+
overlay: 'src/client/overlay.ts',
13+
},
14+
define: {
15+
WEBPACK_HASH: '__webpack_hash__',
16+
},
17+
},
18+
output: {
19+
target: 'web',
20+
externals: ['./hmr'],
21+
distPath: {
22+
root: './dist/client',
23+
},
24+
},
25+
},
26+
],
27+
});

packages/core/src/client/hmr.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function handleErrors(errors: Rspack.StatsError[]) {
120120

121121
// __webpack_hash__ is the hash of the current compilation.
122122
// It's a global variable injected by Rspack.
123-
const isUpdateAvailable = () => lastCompilationHash !== __webpack_hash__;
123+
const isUpdateAvailable = () => lastCompilationHash !== WEBPACK_HASH;
124124

125125
// Attempt to update code on the fly, fall back to a hard reload.
126126
function tryApplyUpdates() {

packages/core/src/env.d.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
declare const RSBUILD_VERSION;
22

3-
declare let RSBUILD_CLIENT_CONFIG: ClientConfig;
3+
declare const WEBPACK_HASH: string;
44

5-
declare let RSBUILD_DEV_LIVE_RELOAD: boolean;
5+
declare const RSBUILD_CLIENT_CONFIG: ClientConfig;
66

7-
declare let RSBUILD_COMPILATION_NAME: string;
7+
declare const RSBUILD_DEV_LIVE_RELOAD: boolean;
8+
9+
declare const RSBUILD_COMPILATION_NAME: string;

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)