@esmx/rspack 3.0.0-rc.58 → 3.0.0-rc.59
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/dist/rspack/app.d.ts +0 -14
- package/dist/rspack/app.mjs +1 -15
- package/dist/rspack/chain-config.mjs +11 -22
- package/package.json +7 -7
- package/src/rspack/app.ts +1 -30
- package/src/rspack/chain-config.ts +11 -31
- package/dist/rspack/config.d.ts +0 -8
- package/dist/rspack/config.mjs +0 -134
- package/dist/rspack/hmr-config.d.ts +0 -2
- package/dist/rspack/hmr-config.mjs +0 -2
- package/dist/rspack/hot-fix.d.ts +0 -0
- package/dist/rspack/hot-fix.mjs +0 -44
- package/src/rspack/config.ts +0 -169
- package/src/rspack/hmr-config.ts +0 -2
- package/src/rspack/hot-fix.ts +0 -51
package/dist/rspack/app.d.ts
CHANGED
|
@@ -20,15 +20,6 @@ import type { BuildTarget } from './build-target';
|
|
|
20
20
|
* // Configuration hook function
|
|
21
21
|
* config(context) {
|
|
22
22
|
* // Access build target
|
|
23
|
-
* if (context.buildTarget === 'client') {
|
|
24
|
-
* // Modify client build configuration
|
|
25
|
-
* context.config.optimization = {
|
|
26
|
-
* ...context.config.optimization,
|
|
27
|
-
* splitChunks: {
|
|
28
|
-
* chunks: 'all'
|
|
29
|
-
* }
|
|
30
|
-
* };
|
|
31
|
-
* }
|
|
32
23
|
* }
|
|
33
24
|
* })
|
|
34
25
|
* );
|
|
@@ -109,11 +100,6 @@ export interface RspackAppChainContext {
|
|
|
109
100
|
* minimize: false,
|
|
110
101
|
* // Custom Rspack configuration
|
|
111
102
|
* config(context) {
|
|
112
|
-
* if (context.buildTarget === 'client') {
|
|
113
|
-
* context.config.optimization.splitChunks = {
|
|
114
|
-
* chunks: 'all'
|
|
115
|
-
* };
|
|
116
|
-
* }
|
|
117
103
|
* }
|
|
118
104
|
* })
|
|
119
105
|
* );
|
package/dist/rspack/app.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
4
2
|
import {
|
|
5
3
|
RenderContext,
|
|
6
4
|
createApp,
|
|
@@ -11,11 +9,6 @@ import hotMiddleware from "webpack-hot-middleware";
|
|
|
11
9
|
import { createRspackConfig } from "./chain-config.mjs";
|
|
12
10
|
import { pack } from "./pack.mjs";
|
|
13
11
|
import { createRsBuild } from "./utils/index.mjs";
|
|
14
|
-
const extension = path.extname(fileURLToPath(import.meta.url));
|
|
15
|
-
const hotFixCode = fs.readFileSync(
|
|
16
|
-
fileURLToPath(new URL(`./hot-fix${extension}`, import.meta.url)),
|
|
17
|
-
"utf-8"
|
|
18
|
-
);
|
|
19
12
|
export async function createRspackApp(esmx, options) {
|
|
20
13
|
const app = await createApp(esmx, esmx.command);
|
|
21
14
|
switch (esmx.command) {
|
|
@@ -77,13 +70,6 @@ function rewriteRender(esmx) {
|
|
|
77
70
|
const serverRender = module[rc.entryName];
|
|
78
71
|
if (typeof serverRender === "function") {
|
|
79
72
|
await serverRender(rc);
|
|
80
|
-
rc.html = rc.html.replace(
|
|
81
|
-
"</head>",
|
|
82
|
-
`
|
|
83
|
-
<script type="module">${hotFixCode}<\/script>
|
|
84
|
-
</head>
|
|
85
|
-
`
|
|
86
|
-
);
|
|
87
73
|
}
|
|
88
74
|
return rc;
|
|
89
75
|
};
|
|
@@ -2,7 +2,6 @@ import { moduleLinkPlugin } from "@esmx/rspack-module-link-plugin";
|
|
|
2
2
|
import { rspack } from "@rspack/core";
|
|
3
3
|
import RspackChain from "rspack-chain";
|
|
4
4
|
import nodeExternals from "webpack-node-externals";
|
|
5
|
-
import { HMR_DIR, HMR_JSONP } from "./hmr-config.mjs";
|
|
6
5
|
export function createChainConfig(esmx, buildTarget, options) {
|
|
7
6
|
const isHot = buildTarget === "client" && !esmx.isProd;
|
|
8
7
|
const isClient = buildTarget === "client";
|
|
@@ -19,8 +18,6 @@ export function createChainConfig(esmx, buildTarget, options) {
|
|
|
19
18
|
esmx.isProd ? "chunks/[name].[contenthash:8].final.mjs" : "chunks/[name].mjs"
|
|
20
19
|
).publicPath(
|
|
21
20
|
isClient ? "auto" : `${esmx.basePathPlaceholder}${esmx.basePath}`
|
|
22
|
-
).uniqueName(esmx.varName).hotUpdateGlobal(HMR_JSONP).chunkLoadingGlobal(`${HMR_JSONP}_chunk`).hotUpdateChunkFilename(`${HMR_DIR}/[id].[fullhash].hot-update.mjs`).hotUpdateMainFilename(
|
|
23
|
-
`${HMR_DIR}/[runtime].[fullhash].hot-update.json`
|
|
24
21
|
);
|
|
25
22
|
config.output.set(
|
|
26
23
|
"cssFilename",
|
|
@@ -30,17 +27,17 @@ export function createChainConfig(esmx, buildTarget, options) {
|
|
|
30
27
|
"cssChunkFilename",
|
|
31
28
|
esmx.isProd ? "chunks/[name].[contenthash:8].final.css" : "chunks/[name].css"
|
|
32
29
|
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
switch (buildTarget) {
|
|
31
|
+
case "client":
|
|
32
|
+
config.output.path(esmx.resolvePath("dist/client"));
|
|
33
|
+
break;
|
|
34
|
+
case "server":
|
|
35
|
+
config.output.path(esmx.resolvePath("dist/server"));
|
|
36
|
+
break;
|
|
37
|
+
case "node":
|
|
38
|
+
config.output.path(esmx.resolvePath("dist/node"));
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
44
41
|
config.plugin("progress").use(rspack.ProgressPlugin, [
|
|
45
42
|
{
|
|
46
43
|
prefix: buildTarget
|
|
@@ -51,7 +48,6 @@ export function createChainConfig(esmx, buildTarget, options) {
|
|
|
51
48
|
config.plugin("hmr").use(rspack.HotModuleReplacementPlugin);
|
|
52
49
|
}
|
|
53
50
|
config.module.parser.set("javascript", {
|
|
54
|
-
dynamicImportMode: "lazy",
|
|
55
51
|
url: isClient ? true : "relative"
|
|
56
52
|
});
|
|
57
53
|
config.module.generator.set("asset", {
|
|
@@ -76,13 +72,6 @@ export function createChainConfig(esmx, buildTarget, options) {
|
|
|
76
72
|
})
|
|
77
73
|
]);
|
|
78
74
|
}
|
|
79
|
-
if (!esmx.isProd) {
|
|
80
|
-
config.optimization.splitChunks(false).runtimeChunk(false);
|
|
81
|
-
config.module.parser.set("javascript", {
|
|
82
|
-
...config.module.parser.get("javascript"),
|
|
83
|
-
dynamicImportMode: "eager"
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
75
|
return config;
|
|
87
76
|
}
|
|
88
77
|
function createModuleLinkConfig(esmx, buildTarget) {
|
package/package.json
CHANGED
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@esmx/import": "3.0.0-rc.
|
|
67
|
-
"@esmx/rspack-module-link-plugin": "3.0.0-rc.
|
|
66
|
+
"@esmx/import": "3.0.0-rc.59",
|
|
67
|
+
"@esmx/rspack-module-link-plugin": "3.0.0-rc.59",
|
|
68
68
|
"@npmcli/arborist": "^9.0.1",
|
|
69
|
-
"@rspack/core": "1.
|
|
69
|
+
"@rspack/core": "1.5.2",
|
|
70
70
|
"css-loader": "^7.1.2",
|
|
71
71
|
"less-loader": "^12.2.0",
|
|
72
72
|
"node-polyfill-webpack-plugin": "^4.1.0",
|
|
73
73
|
"pacote": "^21.0.0",
|
|
74
|
-
"rspack-chain": "^1.4.
|
|
74
|
+
"rspack-chain": "^1.4.1",
|
|
75
75
|
"style-loader": "^4.0.0",
|
|
76
76
|
"style-resources-loader": "^1.5.0",
|
|
77
77
|
"webpack-hot-middleware": "^2.26.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@biomejs/biome": "1.9.4",
|
|
83
|
-
"@esmx/core": "3.0.0-rc.
|
|
83
|
+
"@esmx/core": "3.0.0-rc.59",
|
|
84
84
|
"@types/node": "^24.0.0",
|
|
85
85
|
"@types/npmcli__arborist": "^6.3.1",
|
|
86
86
|
"@types/pacote": "^11.1.8",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"unbuild": "3.6.0",
|
|
92
92
|
"vitest": "3.2.4"
|
|
93
93
|
},
|
|
94
|
-
"version": "3.0.0-rc.
|
|
94
|
+
"version": "3.0.0-rc.59",
|
|
95
95
|
"type": "module",
|
|
96
96
|
"private": false,
|
|
97
97
|
"exports": {
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"template",
|
|
111
111
|
"public"
|
|
112
112
|
],
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "d221aba2a43064b5666e714f42904ae80b2b57ad"
|
|
114
114
|
}
|
package/src/rspack/app.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
4
2
|
import {
|
|
5
3
|
type App,
|
|
6
4
|
type Esmx,
|
|
@@ -19,12 +17,6 @@ import { createRspackConfig } from './chain-config';
|
|
|
19
17
|
import { pack } from './pack';
|
|
20
18
|
import { createRsBuild } from './utils';
|
|
21
19
|
|
|
22
|
-
const extension = path.extname(fileURLToPath(import.meta.url));
|
|
23
|
-
const hotFixCode = fs.readFileSync(
|
|
24
|
-
fileURLToPath(new URL(`./hot-fix${extension}`, import.meta.url)),
|
|
25
|
-
'utf-8'
|
|
26
|
-
);
|
|
27
|
-
|
|
28
20
|
/**
|
|
29
21
|
* Rspack application configuration context interface.
|
|
30
22
|
*
|
|
@@ -44,15 +36,6 @@ const hotFixCode = fs.readFileSync(
|
|
|
44
36
|
* // Configuration hook function
|
|
45
37
|
* config(context) {
|
|
46
38
|
* // Access build target
|
|
47
|
-
* if (context.buildTarget === 'client') {
|
|
48
|
-
* // Modify client build configuration
|
|
49
|
-
* context.config.optimization = {
|
|
50
|
-
* ...context.config.optimization,
|
|
51
|
-
* splitChunks: {
|
|
52
|
-
* chunks: 'all'
|
|
53
|
-
* }
|
|
54
|
-
* };
|
|
55
|
-
* }
|
|
56
39
|
* }
|
|
57
40
|
* })
|
|
58
41
|
* );
|
|
@@ -141,11 +124,6 @@ export interface RspackAppChainContext {
|
|
|
141
124
|
* minimize: false,
|
|
142
125
|
* // Custom Rspack configuration
|
|
143
126
|
* config(context) {
|
|
144
|
-
* if (context.buildTarget === 'client') {
|
|
145
|
-
* context.config.optimization.splitChunks = {
|
|
146
|
-
* chunks: 'all'
|
|
147
|
-
* };
|
|
148
|
-
* }
|
|
149
127
|
* }
|
|
150
128
|
* })
|
|
151
129
|
* );
|
|
@@ -305,13 +283,6 @@ function rewriteRender(esmx: Esmx) {
|
|
|
305
283
|
const serverRender: ServerRenderHandle = module[rc.entryName];
|
|
306
284
|
if (typeof serverRender === 'function') {
|
|
307
285
|
await serverRender(rc);
|
|
308
|
-
rc.html = rc.html.replace(
|
|
309
|
-
'</head>',
|
|
310
|
-
`
|
|
311
|
-
<script type="module">${hotFixCode}</script>
|
|
312
|
-
</head>
|
|
313
|
-
`
|
|
314
|
-
);
|
|
315
286
|
}
|
|
316
287
|
return rc;
|
|
317
288
|
};
|
|
@@ -6,7 +6,6 @@ import RspackChain from 'rspack-chain';
|
|
|
6
6
|
import nodeExternals from 'webpack-node-externals';
|
|
7
7
|
import type { RspackAppOptions } from './app';
|
|
8
8
|
import type { BuildTarget } from './build-target';
|
|
9
|
-
import { HMR_DIR, HMR_JSONP } from './hmr-config';
|
|
10
9
|
|
|
11
10
|
export function createChainConfig(
|
|
12
11
|
esmx: Esmx,
|
|
@@ -39,13 +38,6 @@ export function createChainConfig(
|
|
|
39
38
|
)
|
|
40
39
|
.publicPath(
|
|
41
40
|
isClient ? 'auto' : `${esmx.basePathPlaceholder}${esmx.basePath}`
|
|
42
|
-
)
|
|
43
|
-
.uniqueName(esmx.varName)
|
|
44
|
-
.hotUpdateGlobal(HMR_JSONP)
|
|
45
|
-
.chunkLoadingGlobal(`${HMR_JSONP}_chunk`)
|
|
46
|
-
.hotUpdateChunkFilename(`${HMR_DIR}/[id].[fullhash].hot-update.mjs`)
|
|
47
|
-
.hotUpdateMainFilename(
|
|
48
|
-
`${HMR_DIR}/[runtime].[fullhash].hot-update.json`
|
|
49
41
|
);
|
|
50
42
|
|
|
51
43
|
config.output.set(
|
|
@@ -61,17 +53,17 @@ export function createChainConfig(
|
|
|
61
53
|
: 'chunks/[name].css'
|
|
62
54
|
);
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
56
|
+
switch (buildTarget) {
|
|
57
|
+
case 'client':
|
|
58
|
+
config.output.path(esmx.resolvePath('dist/client'));
|
|
59
|
+
break;
|
|
60
|
+
case 'server':
|
|
61
|
+
config.output.path(esmx.resolvePath('dist/server'));
|
|
62
|
+
break;
|
|
63
|
+
case 'node':
|
|
64
|
+
config.output.path(esmx.resolvePath('dist/node'));
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
75
67
|
|
|
76
68
|
config.plugin('progress').use(rspack.ProgressPlugin, [
|
|
77
69
|
{
|
|
@@ -88,7 +80,6 @@ export function createChainConfig(
|
|
|
88
80
|
}
|
|
89
81
|
|
|
90
82
|
config.module.parser.set('javascript', {
|
|
91
|
-
dynamicImportMode: 'lazy',
|
|
92
83
|
url: isClient ? true : 'relative'
|
|
93
84
|
});
|
|
94
85
|
|
|
@@ -122,17 +113,6 @@ export function createChainConfig(
|
|
|
122
113
|
]);
|
|
123
114
|
}
|
|
124
115
|
|
|
125
|
-
// Temporary fix for development environment
|
|
126
|
-
// Related issue: https://github.com/esmnext/esmx/issues/109
|
|
127
|
-
// TODO: Remove when Rspack officially supports these features
|
|
128
|
-
if (!esmx.isProd) {
|
|
129
|
-
config.optimization.splitChunks(false).runtimeChunk(false);
|
|
130
|
-
config.module.parser.set('javascript', {
|
|
131
|
-
...config.module.parser.get('javascript'),
|
|
132
|
-
dynamicImportMode: 'eager'
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
116
|
return config;
|
|
137
117
|
}
|
|
138
118
|
|
package/dist/rspack/config.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Esmx } from '@esmx/core';
|
|
2
|
-
import { type RspackOptions } from '@rspack/core';
|
|
3
|
-
import type { RspackAppOptions } from './app';
|
|
4
|
-
import type { BuildTarget } from './build-target';
|
|
5
|
-
/**
|
|
6
|
-
* Base configuration for building Client, Server, and Node targets
|
|
7
|
-
*/
|
|
8
|
-
export declare function createRspackConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackOptions;
|
package/dist/rspack/config.mjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { moduleLinkPlugin } from "@esmx/rspack-module-link-plugin";
|
|
2
|
-
import {
|
|
3
|
-
rspack
|
|
4
|
-
} from "@rspack/core";
|
|
5
|
-
import nodeExternals from "webpack-node-externals";
|
|
6
|
-
import { HMR_DIR, HMR_JSONP } from "./hmr-config.mjs";
|
|
7
|
-
export function createRspackConfig(esmx, buildTarget, options) {
|
|
8
|
-
const isHot = buildTarget === "client" && !esmx.isProd;
|
|
9
|
-
return {
|
|
10
|
-
/**
|
|
11
|
-
* Project root directory, cannot be modified
|
|
12
|
-
*/
|
|
13
|
-
context: esmx.root,
|
|
14
|
-
output: {
|
|
15
|
-
clean: esmx.isProd,
|
|
16
|
-
filename: buildTarget !== "node" && esmx.isProd ? "exports/[name].[contenthash:8].final.mjs" : "exports/[name].mjs",
|
|
17
|
-
cssFilename: esmx.isProd ? "exports/[name].[contenthash:8].final.css" : "exports/[name].css",
|
|
18
|
-
chunkFilename: esmx.isProd ? "chunks/[name].[contenthash:8].final.mjs" : "chunks/[name].mjs",
|
|
19
|
-
cssChunkFilename: esmx.isProd ? "chunks/[name].[contenthash:8].final.css" : "chunks/[name].css",
|
|
20
|
-
publicPath: buildTarget === "client" ? "auto" : `${esmx.basePathPlaceholder}${esmx.basePath}`,
|
|
21
|
-
uniqueName: esmx.varName,
|
|
22
|
-
hotUpdateGlobal: HMR_JSONP,
|
|
23
|
-
chunkLoadingGlobal: HMR_JSONP + "_chunk",
|
|
24
|
-
hotUpdateChunkFilename: `${HMR_DIR}/[id].[fullhash].hot-update.mjs`,
|
|
25
|
-
hotUpdateMainFilename: `${HMR_DIR}/[runtime].[fullhash].hot-update.json`,
|
|
26
|
-
path: (() => {
|
|
27
|
-
switch (buildTarget) {
|
|
28
|
-
case "client":
|
|
29
|
-
return esmx.resolvePath("dist/client");
|
|
30
|
-
case "server":
|
|
31
|
-
return esmx.resolvePath("dist/server");
|
|
32
|
-
case "node":
|
|
33
|
-
return esmx.resolvePath("dist/node");
|
|
34
|
-
}
|
|
35
|
-
})()
|
|
36
|
-
},
|
|
37
|
-
plugins: (() => {
|
|
38
|
-
return [
|
|
39
|
-
new rspack.ProgressPlugin({
|
|
40
|
-
prefix: buildTarget
|
|
41
|
-
}),
|
|
42
|
-
createModuleLinkPlugin(esmx, buildTarget),
|
|
43
|
-
isHot ? new rspack.HotModuleReplacementPlugin() : false
|
|
44
|
-
];
|
|
45
|
-
})(),
|
|
46
|
-
module: {
|
|
47
|
-
parser: {
|
|
48
|
-
javascript: {
|
|
49
|
-
// DEV hot update fix
|
|
50
|
-
dynamicImportMode: esmx.isProd ? "lazy" : "eager",
|
|
51
|
-
url: buildTarget === "client" ? true : "relative"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
generator: {
|
|
55
|
-
asset: {
|
|
56
|
-
emit: buildTarget === "client"
|
|
57
|
-
},
|
|
58
|
-
"asset/resource": {
|
|
59
|
-
emit: buildTarget === "client"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
rules: []
|
|
63
|
-
},
|
|
64
|
-
resolve: {
|
|
65
|
-
alias: {
|
|
66
|
-
[esmx.name]: esmx.root
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
optimization: {
|
|
70
|
-
minimize: options.minimize ?? esmx.isProd,
|
|
71
|
-
emitOnErrors: true,
|
|
72
|
-
// DEV hot update fix
|
|
73
|
-
splitChunks: esmx.isProd ? void 0 : false,
|
|
74
|
-
// DEV hot update fix
|
|
75
|
-
runtimeChunk: esmx.isProd ? void 0 : false
|
|
76
|
-
},
|
|
77
|
-
externalsPresets: {
|
|
78
|
-
web: buildTarget === "client",
|
|
79
|
-
node: buildTarget === "server" || buildTarget === "node"
|
|
80
|
-
},
|
|
81
|
-
externalsType: "module-import",
|
|
82
|
-
externals: (() => {
|
|
83
|
-
if (buildTarget === "node") {
|
|
84
|
-
return [
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
nodeExternals({
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
importType: "module-import"
|
|
89
|
-
})
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
return [];
|
|
93
|
-
})(),
|
|
94
|
-
target: buildTarget === "client" ? "web" : "node24",
|
|
95
|
-
mode: esmx.isProd ? "production" : "development",
|
|
96
|
-
cache: !esmx.isProd
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function createModuleLinkPlugin(esmx, buildTarget) {
|
|
100
|
-
if (buildTarget === "node") {
|
|
101
|
-
return moduleLinkPlugin({
|
|
102
|
-
name: esmx.name,
|
|
103
|
-
exports: {
|
|
104
|
-
"src/entry.node": {
|
|
105
|
-
rewrite: false,
|
|
106
|
-
file: "./src/entry.node"
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const exports = {};
|
|
112
|
-
for (const [name, item] of Object.entries(esmx.moduleConfig.exports)) {
|
|
113
|
-
if (item.entryPoints[buildTarget]) {
|
|
114
|
-
exports[name] = {
|
|
115
|
-
rewrite: item.rewrite,
|
|
116
|
-
file: item.entryPoints[buildTarget]
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const preEntries = [];
|
|
121
|
-
if (buildTarget === "client" && !esmx.isProd) {
|
|
122
|
-
preEntries.push(
|
|
123
|
-
`${import.meta.resolve("webpack-hot-middleware/client.js")}?path=/${esmx.name}/hot-middleware`
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
return moduleLinkPlugin({
|
|
127
|
-
name: esmx.name,
|
|
128
|
-
injectChunkName: buildTarget === "server",
|
|
129
|
-
imports: esmx.moduleConfig.imports,
|
|
130
|
-
deps: Object.keys(esmx.moduleConfig.links),
|
|
131
|
-
exports,
|
|
132
|
-
preEntries
|
|
133
|
-
});
|
|
134
|
-
}
|
package/dist/rspack/hot-fix.d.ts
DELETED
|
File without changes
|
package/dist/rspack/hot-fix.mjs
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
const HMR_JSONP = "__esmx_rspack_hmr_jsonp__";
|
|
3
|
-
const HMR_JSONP_LIST = "__esmx_rspack_hmr_jsonp_list__";
|
|
4
|
-
const list = window[HMR_JSONP_LIST] = window[HMR_JSONP_LIST] || [];
|
|
5
|
-
Object.defineProperty(window, HMR_JSONP, {
|
|
6
|
-
get() {
|
|
7
|
-
return (...args) => {
|
|
8
|
-
const hotUrl = getStackUrl(new Error().stack || "", 1);
|
|
9
|
-
if (hotUrl) {
|
|
10
|
-
const item = list.find(
|
|
11
|
-
(item2) => isSameModule(hotUrl, item2.url)
|
|
12
|
-
);
|
|
13
|
-
if (item) {
|
|
14
|
-
return item.jsonp(...args);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
console.log("%chot update not found", "color: red", args);
|
|
18
|
-
};
|
|
19
|
-
},
|
|
20
|
-
set(jsonp) {
|
|
21
|
-
const url = getStackUrl(new Error().stack || "", 1);
|
|
22
|
-
if (url) {
|
|
23
|
-
list.push({ url, jsonp });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
function isSameModule(hotUrl, originalUrl) {
|
|
28
|
-
const normalizedHotUrl = hotUrl.replace(/\/__hot__\//, "/exports/").replace(/\.\w+\.hot-update\.mjs$/, ".mjs");
|
|
29
|
-
const normalizedOriginalUrl = originalUrl;
|
|
30
|
-
return normalizedHotUrl === normalizedOriginalUrl;
|
|
31
|
-
}
|
|
32
|
-
function getStackUrl(stack, index = 0) {
|
|
33
|
-
const lines = stack.split("\n");
|
|
34
|
-
const stackLines = lines.filter((line2) => line2.includes("at "));
|
|
35
|
-
if (index < 0 || index >= stackLines.length) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const line = stackLines[index];
|
|
39
|
-
const withoutAt = line.replace(/^\s*at\s+/, "");
|
|
40
|
-
const urlMatch = withoutAt.match(/\((.*?)\)/);
|
|
41
|
-
const url = urlMatch ? urlMatch[1] : withoutAt;
|
|
42
|
-
return url.replace(/:\d+:\d+$/, "");
|
|
43
|
-
}
|
|
44
|
-
})();
|
package/src/rspack/config.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import type { Esmx } from '@esmx/core';
|
|
2
|
-
import { moduleLinkPlugin } from '@esmx/rspack-module-link-plugin';
|
|
3
|
-
import {
|
|
4
|
-
type ExternalItem,
|
|
5
|
-
type Plugin,
|
|
6
|
-
type Plugins,
|
|
7
|
-
type RspackOptions,
|
|
8
|
-
rspack
|
|
9
|
-
} from '@rspack/core';
|
|
10
|
-
import nodeExternals from 'webpack-node-externals';
|
|
11
|
-
import type { RspackAppOptions } from './app';
|
|
12
|
-
import type { BuildTarget } from './build-target';
|
|
13
|
-
import { HMR_DIR, HMR_JSONP } from './hmr-config';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Base configuration for building Client, Server, and Node targets
|
|
17
|
-
*/
|
|
18
|
-
export function createRspackConfig(
|
|
19
|
-
esmx: Esmx,
|
|
20
|
-
buildTarget: BuildTarget,
|
|
21
|
-
options: RspackAppOptions
|
|
22
|
-
): RspackOptions {
|
|
23
|
-
const isHot = buildTarget === 'client' && !esmx.isProd;
|
|
24
|
-
return {
|
|
25
|
-
/**
|
|
26
|
-
* Project root directory, cannot be modified
|
|
27
|
-
*/
|
|
28
|
-
context: esmx.root,
|
|
29
|
-
output: {
|
|
30
|
-
clean: esmx.isProd,
|
|
31
|
-
filename:
|
|
32
|
-
buildTarget !== 'node' && esmx.isProd
|
|
33
|
-
? 'exports/[name].[contenthash:8].final.mjs'
|
|
34
|
-
: 'exports/[name].mjs',
|
|
35
|
-
cssFilename: esmx.isProd
|
|
36
|
-
? 'exports/[name].[contenthash:8].final.css'
|
|
37
|
-
: 'exports/[name].css',
|
|
38
|
-
chunkFilename: esmx.isProd
|
|
39
|
-
? 'chunks/[name].[contenthash:8].final.mjs'
|
|
40
|
-
: 'chunks/[name].mjs',
|
|
41
|
-
cssChunkFilename: esmx.isProd
|
|
42
|
-
? 'chunks/[name].[contenthash:8].final.css'
|
|
43
|
-
: 'chunks/[name].css',
|
|
44
|
-
publicPath:
|
|
45
|
-
buildTarget === 'client'
|
|
46
|
-
? 'auto'
|
|
47
|
-
: `${esmx.basePathPlaceholder}${esmx.basePath}`,
|
|
48
|
-
uniqueName: esmx.varName,
|
|
49
|
-
hotUpdateGlobal: HMR_JSONP,
|
|
50
|
-
chunkLoadingGlobal: HMR_JSONP + '_chunk',
|
|
51
|
-
hotUpdateChunkFilename: `${HMR_DIR}/[id].[fullhash].hot-update.mjs`,
|
|
52
|
-
hotUpdateMainFilename: `${HMR_DIR}/[runtime].[fullhash].hot-update.json`,
|
|
53
|
-
path: ((): string => {
|
|
54
|
-
switch (buildTarget) {
|
|
55
|
-
case 'client':
|
|
56
|
-
return esmx.resolvePath('dist/client');
|
|
57
|
-
case 'server':
|
|
58
|
-
return esmx.resolvePath('dist/server');
|
|
59
|
-
case 'node':
|
|
60
|
-
return esmx.resolvePath('dist/node');
|
|
61
|
-
}
|
|
62
|
-
})()
|
|
63
|
-
},
|
|
64
|
-
plugins: ((): Plugins => {
|
|
65
|
-
return [
|
|
66
|
-
new rspack.ProgressPlugin({
|
|
67
|
-
prefix: buildTarget
|
|
68
|
-
}),
|
|
69
|
-
createModuleLinkPlugin(esmx, buildTarget),
|
|
70
|
-
isHot ? new rspack.HotModuleReplacementPlugin() : false
|
|
71
|
-
];
|
|
72
|
-
})(),
|
|
73
|
-
module: {
|
|
74
|
-
parser: {
|
|
75
|
-
javascript: {
|
|
76
|
-
// DEV hot update fix
|
|
77
|
-
dynamicImportMode: esmx.isProd ? 'lazy' : 'eager',
|
|
78
|
-
url: buildTarget === 'client' ? true : 'relative'
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
generator: {
|
|
82
|
-
asset: {
|
|
83
|
-
emit: buildTarget === 'client'
|
|
84
|
-
},
|
|
85
|
-
'asset/resource': {
|
|
86
|
-
emit: buildTarget === 'client'
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
rules: []
|
|
90
|
-
},
|
|
91
|
-
resolve: {
|
|
92
|
-
alias: {
|
|
93
|
-
[esmx.name]: esmx.root
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
optimization: {
|
|
97
|
-
minimize: options.minimize ?? esmx.isProd,
|
|
98
|
-
emitOnErrors: true,
|
|
99
|
-
// DEV hot update fix
|
|
100
|
-
splitChunks: esmx.isProd ? undefined : false,
|
|
101
|
-
// DEV hot update fix
|
|
102
|
-
runtimeChunk: esmx.isProd ? undefined : false
|
|
103
|
-
},
|
|
104
|
-
externalsPresets: {
|
|
105
|
-
web: buildTarget === 'client',
|
|
106
|
-
node: buildTarget === 'server' || buildTarget === 'node'
|
|
107
|
-
},
|
|
108
|
-
externalsType: 'module-import',
|
|
109
|
-
externals: ((): ExternalItem[] => {
|
|
110
|
-
if (buildTarget === 'node') {
|
|
111
|
-
return [
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
nodeExternals({
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
importType: 'module-import'
|
|
116
|
-
})
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
return [];
|
|
120
|
-
})(),
|
|
121
|
-
target: buildTarget === 'client' ? 'web' : 'node24',
|
|
122
|
-
mode: esmx.isProd ? 'production' : 'development',
|
|
123
|
-
cache: !esmx.isProd
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function createModuleLinkPlugin(esmx: Esmx, buildTarget: BuildTarget): Plugin {
|
|
128
|
-
if (buildTarget === 'node') {
|
|
129
|
-
return moduleLinkPlugin({
|
|
130
|
-
name: esmx.name,
|
|
131
|
-
exports: {
|
|
132
|
-
'src/entry.node': {
|
|
133
|
-
rewrite: false,
|
|
134
|
-
file: './src/entry.node'
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
const exports: Record<
|
|
140
|
-
string,
|
|
141
|
-
{
|
|
142
|
-
rewrite: boolean;
|
|
143
|
-
file: string;
|
|
144
|
-
}
|
|
145
|
-
> = {};
|
|
146
|
-
for (const [name, item] of Object.entries(esmx.moduleConfig.exports)) {
|
|
147
|
-
if (item.entryPoints[buildTarget]) {
|
|
148
|
-
exports[name] = {
|
|
149
|
-
rewrite: item.rewrite,
|
|
150
|
-
file: item.entryPoints[buildTarget]
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const preEntries: string[] = [];
|
|
155
|
-
if (buildTarget === 'client' && !esmx.isProd) {
|
|
156
|
-
preEntries.push(
|
|
157
|
-
`${import.meta.resolve('webpack-hot-middleware/client.js')}?path=/${esmx.name}/hot-middleware`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return moduleLinkPlugin({
|
|
162
|
-
name: esmx.name,
|
|
163
|
-
injectChunkName: buildTarget === 'server',
|
|
164
|
-
imports: esmx.moduleConfig.imports,
|
|
165
|
-
deps: Object.keys(esmx.moduleConfig.links),
|
|
166
|
-
exports,
|
|
167
|
-
preEntries
|
|
168
|
-
});
|
|
169
|
-
}
|
package/src/rspack/hmr-config.ts
DELETED
package/src/rspack/hot-fix.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
const HMR_JSONP = '__esmx_rspack_hmr_jsonp__';
|
|
3
|
-
const HMR_JSONP_LIST = '__esmx_rspack_hmr_jsonp_list__';
|
|
4
|
-
|
|
5
|
-
const list: Array<{ url: string; jsonp: Function }> = (window[
|
|
6
|
-
HMR_JSONP_LIST
|
|
7
|
-
] = window[HMR_JSONP_LIST] || []);
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(window, HMR_JSONP, {
|
|
10
|
-
get() {
|
|
11
|
-
return (...args: any[]) => {
|
|
12
|
-
const hotUrl = getStackUrl(new Error().stack || '', 1);
|
|
13
|
-
if (hotUrl) {
|
|
14
|
-
const item = list.find((item) =>
|
|
15
|
-
isSameModule(hotUrl, item.url)
|
|
16
|
-
);
|
|
17
|
-
if (item) {
|
|
18
|
-
return item.jsonp(...args);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
console.log('%chot update not found', 'color: red', args);
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
set(jsonp) {
|
|
25
|
-
const url = getStackUrl(new Error().stack || '', 1);
|
|
26
|
-
if (url) {
|
|
27
|
-
list.push({ url, jsonp });
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
function isSameModule(hotUrl: string, originalUrl: string): boolean {
|
|
32
|
-
const normalizedHotUrl = hotUrl
|
|
33
|
-
.replace(/\/__hot__\//, '/exports/')
|
|
34
|
-
.replace(/\.\w+\.hot-update\.mjs$/, '.mjs');
|
|
35
|
-
const normalizedOriginalUrl = originalUrl;
|
|
36
|
-
return normalizedHotUrl === normalizedOriginalUrl;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function getStackUrl(stack: string, index = 0): string | null {
|
|
40
|
-
const lines = stack.split('\n');
|
|
41
|
-
const stackLines = lines.filter((line) => line.includes('at '));
|
|
42
|
-
if (index < 0 || index >= stackLines.length) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const line = stackLines[index];
|
|
46
|
-
const withoutAt = line.replace(/^\s*at\s+/, '');
|
|
47
|
-
const urlMatch = withoutAt.match(/\((.*?)\)/);
|
|
48
|
-
const url = urlMatch ? urlMatch[1] : withoutAt;
|
|
49
|
-
return url.replace(/:\d+:\d+$/, '');
|
|
50
|
-
}
|
|
51
|
-
})();
|