@esmx/rspack 3.0.0-rc.77 → 3.0.0-rc.79
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/index.d.ts +1 -1
- package/dist/module-link/config.d.ts +5 -0
- package/dist/module-link/config.mjs +100 -0
- package/dist/module-link/config1.d.ts +3 -0
- package/dist/module-link/config1.mjs +16 -0
- package/dist/module-link/config2.d.ts +3 -0
- package/dist/module-link/config2.mjs +17 -0
- package/dist/module-link/index.d.ts +4 -0
- package/dist/module-link/index.mjs +8 -0
- package/dist/module-link/manifest-plugin.d.ts +14 -0
- package/dist/module-link/manifest-plugin.mjs +141 -0
- package/dist/module-link/parse.d.ts +2 -0
- package/dist/module-link/parse.mjs +24 -0
- package/dist/module-link/types.d.ts +25 -0
- package/dist/module-link/types.mjs +0 -0
- package/dist/rspack/app.mjs +5 -10
- package/dist/rspack/chain-config.mjs +36 -29
- package/dist/rspack/index.d.ts +1 -1
- package/dist/rspack-html/index.mjs +2 -2
- package/dist/rspack-html/target-setting.test.mjs +1 -1
- package/package.json +7 -7
- package/src/index.ts +4 -4
- package/src/module-link/config.ts +157 -0
- package/src/module-link/config1.ts +24 -0
- package/src/module-link/config2.ts +28 -0
- package/src/module-link/index.ts +19 -0
- package/src/module-link/manifest-plugin.ts +179 -0
- package/src/module-link/parse.ts +31 -0
- package/src/module-link/types.ts +31 -0
- package/src/rspack/app.ts +8 -13
- package/src/rspack/chain-config.ts +40 -34
- package/src/rspack/index.ts +3 -3
- package/src/rspack-html/index.ts +5 -5
- package/src/rspack-html/target-setting.test.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { type BuildTarget, createRspackApp, RSPACK_LOADER, type RspackAppChainContext, type RspackAppConfigContext, type RspackAppOptions } from './rspack';
|
|
2
2
|
export { createRspackHtmlApp, type RspackHtmlAppOptions } from './rspack-html';
|
|
3
3
|
import * as rspack from '@rspack/core';
|
|
4
4
|
export { rspack };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type RspackChain from 'rspack-chain';
|
|
2
|
+
import type { ParsedModuleLinkPluginOptions } from './types';
|
|
3
|
+
export declare function applyEntryConfig(chain: RspackChain, opts: ParsedModuleLinkPluginOptions): void;
|
|
4
|
+
export declare function applyModuleConfig(chain: RspackChain): void;
|
|
5
|
+
export declare function applyExternalsConfig(chain: RspackChain, opts: ParsedModuleLinkPluginOptions): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export function applyEntryConfig(chain, opts) {
|
|
2
|
+
if (chain.entryPoints.has("main")) {
|
|
3
|
+
const mainEntry = chain.entry("main");
|
|
4
|
+
if (mainEntry.values().length === 0) {
|
|
5
|
+
chain.entryPoints.clear();
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
for (const value of Object.values(opts.exports)) {
|
|
9
|
+
if (value.file) {
|
|
10
|
+
const entry = chain.entry(value.name);
|
|
11
|
+
for (const preEntry of opts.preEntries) {
|
|
12
|
+
entry.add(preEntry);
|
|
13
|
+
}
|
|
14
|
+
entry.add(value.file);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function applyModuleConfig(chain) {
|
|
19
|
+
chain.output.set("module", true).set("chunkFormat", "module").set("chunkLoading", "import").set("workerChunkLoading", "import");
|
|
20
|
+
chain.output.library({
|
|
21
|
+
type: "module"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function applyExternalsConfig(chain, opts) {
|
|
25
|
+
const existingExternals = chain.get("externals") || [];
|
|
26
|
+
const externals = Array.isArray(existingExternals) ? [...existingExternals] : [existingExternals];
|
|
27
|
+
const compilerContext = chain.get("context") ?? process.cwd();
|
|
28
|
+
const externalFunc = createExternalsFunction(opts, compilerContext);
|
|
29
|
+
externals.push(externalFunc);
|
|
30
|
+
chain.externals(externals);
|
|
31
|
+
}
|
|
32
|
+
function createExternalsFunction(opts, compilerContext) {
|
|
33
|
+
const importMap = /* @__PURE__ */ new Map();
|
|
34
|
+
let initPromise = null;
|
|
35
|
+
const init = (resolvePath) => {
|
|
36
|
+
if (initPromise) return initPromise;
|
|
37
|
+
initPromise = (async () => {
|
|
38
|
+
await Promise.all(
|
|
39
|
+
Object.values(opts.exports).map(async (value) => {
|
|
40
|
+
const identifier = value.pkg ? value.name : value.identifier;
|
|
41
|
+
importMap.set(identifier, identifier);
|
|
42
|
+
importMap.set(value.name, identifier);
|
|
43
|
+
const resolvedPath = await resolvePath(value.file);
|
|
44
|
+
if (resolvedPath) {
|
|
45
|
+
importMap.set(resolvedPath, identifier);
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
for (const key of Object.keys(opts.imports)) {
|
|
50
|
+
importMap.set(key, key);
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
return initPromise;
|
|
54
|
+
};
|
|
55
|
+
const match = async (request, context, resolvePath) => {
|
|
56
|
+
if (!request) return null;
|
|
57
|
+
if (opts.deps.length > 0) {
|
|
58
|
+
const matchedDep = opts.deps.find(
|
|
59
|
+
(dep) => request === dep || request.startsWith(`${dep}/`)
|
|
60
|
+
);
|
|
61
|
+
if (matchedDep) {
|
|
62
|
+
return request;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let importName = importMap.get(request);
|
|
66
|
+
if (!importName) {
|
|
67
|
+
const resolvedPath = await resolvePath(request, context);
|
|
68
|
+
if (resolvedPath) {
|
|
69
|
+
importName = importMap.get(resolvedPath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return importName || null;
|
|
73
|
+
};
|
|
74
|
+
const FILE_EXT_REGEX = /\.worker\.(js|mjs|cjs|jsx|mjsx|cjsx|ts|mts|cts|tsx|mtsx|ctsx)$/i;
|
|
75
|
+
return async (data) => {
|
|
76
|
+
if (!data.request || !data.context || !data.contextInfo?.issuer || FILE_EXT_REGEX.test(data.contextInfo.issuer))
|
|
77
|
+
return;
|
|
78
|
+
const defaultContext = compilerContext;
|
|
79
|
+
const resolvePath = async (request, context = defaultContext) => {
|
|
80
|
+
if (!data.getResolve) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const resolveFunc = data.getResolve();
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
resolveFunc(context, request, (err, res) => {
|
|
86
|
+
resolve(typeof res === "string" ? res : null);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
await init(resolvePath);
|
|
91
|
+
const matchedIdentifier = await match(
|
|
92
|
+
data.request,
|
|
93
|
+
data.context,
|
|
94
|
+
resolvePath
|
|
95
|
+
);
|
|
96
|
+
if (matchedIdentifier) {
|
|
97
|
+
return `module-import ${matchedIdentifier}`;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyEntryConfig,
|
|
3
|
+
applyExternalsConfig,
|
|
4
|
+
applyModuleConfig
|
|
5
|
+
} from "./config.mjs";
|
|
6
|
+
export function applyChainConfig1(chain, opts) {
|
|
7
|
+
applyEntryConfig(chain, opts);
|
|
8
|
+
applyExternalsConfig(chain, opts);
|
|
9
|
+
applyModuleConfig(chain);
|
|
10
|
+
if (chain.get("mode") === "production") {
|
|
11
|
+
chain.output.library({
|
|
12
|
+
type: "modern-module"
|
|
13
|
+
});
|
|
14
|
+
chain.optimization.set("avoidEntryIife", true);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { rspack } from "@rspack/core";
|
|
2
|
+
import {
|
|
3
|
+
applyEntryConfig,
|
|
4
|
+
applyExternalsConfig,
|
|
5
|
+
applyModuleConfig
|
|
6
|
+
} from "./config.mjs";
|
|
7
|
+
export function applyChainConfig2(chain, opts) {
|
|
8
|
+
applyEntryConfig(chain, opts);
|
|
9
|
+
applyExternalsConfig(chain, opts);
|
|
10
|
+
if (chain.get("mode") === "production") {
|
|
11
|
+
chain.output.set("module", true);
|
|
12
|
+
chain.plugin("esm-library").use(new rspack.experiments.EsmLibraryPlugin());
|
|
13
|
+
chain.optimization.set("runtimeChunk", "single");
|
|
14
|
+
} else {
|
|
15
|
+
applyModuleConfig(chain);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { applyChainConfig1 } from "./config1.mjs";
|
|
2
|
+
import { ManifestPlugin } from "./manifest-plugin.mjs";
|
|
3
|
+
import { parseOptions } from "./parse.mjs";
|
|
4
|
+
export function initModuleLink(chain, options) {
|
|
5
|
+
const opts = parseOptions(options);
|
|
6
|
+
applyChainConfig1(chain, opts);
|
|
7
|
+
chain.plugin("module-link-manifest").use(ManifestPlugin, [opts]);
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Compiler, StatsCompilation } from '@rspack/core';
|
|
2
|
+
import type { ManifestJsonExports, ParsedModuleLinkPluginOptions } from './types';
|
|
3
|
+
export declare const RSPACK_PLUGIN_NAME = "rspack-module-link-plugin";
|
|
4
|
+
export declare class ManifestPlugin {
|
|
5
|
+
private opts;
|
|
6
|
+
constructor(opts: ParsedModuleLinkPluginOptions);
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function getExports(opts: ParsedModuleLinkPluginOptions, stats: StatsCompilation): ManifestJsonExports;
|
|
10
|
+
export declare function generateIdentifier({ root, name, filePath }: {
|
|
11
|
+
root: string;
|
|
12
|
+
name: string;
|
|
13
|
+
filePath: string;
|
|
14
|
+
}): string;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import upath from "upath";
|
|
2
|
+
export const RSPACK_PLUGIN_NAME = "rspack-module-link-plugin";
|
|
3
|
+
export class ManifestPlugin {
|
|
4
|
+
constructor(opts) {
|
|
5
|
+
this.opts = opts;
|
|
6
|
+
}
|
|
7
|
+
apply(compiler) {
|
|
8
|
+
const opts = this.opts;
|
|
9
|
+
const { Compilation } = compiler.rspack;
|
|
10
|
+
compiler.hooks.thisCompilation.tap(
|
|
11
|
+
RSPACK_PLUGIN_NAME,
|
|
12
|
+
(compilation) => {
|
|
13
|
+
let manifestJson = {
|
|
14
|
+
name: opts.name,
|
|
15
|
+
exports: {},
|
|
16
|
+
scopes: opts.scopes,
|
|
17
|
+
files: [],
|
|
18
|
+
chunks: {}
|
|
19
|
+
};
|
|
20
|
+
compilation.hooks.processAssets.tap(
|
|
21
|
+
{
|
|
22
|
+
name: RSPACK_PLUGIN_NAME,
|
|
23
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
24
|
+
},
|
|
25
|
+
(assets) => {
|
|
26
|
+
const stats = compilation.getStats().toJson({
|
|
27
|
+
hash: true,
|
|
28
|
+
entrypoints: true
|
|
29
|
+
});
|
|
30
|
+
const exports = getExports(opts, stats);
|
|
31
|
+
const resources = Object.keys(assets).map(transFileName).filter((file) => !file.includes("hot-update"));
|
|
32
|
+
manifestJson = {
|
|
33
|
+
name: opts.name,
|
|
34
|
+
exports,
|
|
35
|
+
scopes: opts.scopes,
|
|
36
|
+
files: resources,
|
|
37
|
+
chunks: getChunks(opts, compilation)
|
|
38
|
+
};
|
|
39
|
+
const { RawSource } = compiler.rspack.sources;
|
|
40
|
+
compilation.emitAsset(
|
|
41
|
+
"manifest.json",
|
|
42
|
+
new RawSource(JSON.stringify(manifestJson, null, 4))
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
if (opts.injectChunkName) {
|
|
47
|
+
compilation.hooks.processAssets.tap(
|
|
48
|
+
{
|
|
49
|
+
name: RSPACK_PLUGIN_NAME,
|
|
50
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
|
|
51
|
+
},
|
|
52
|
+
(assets) => {
|
|
53
|
+
const { RawSource } = compiler.rspack.sources;
|
|
54
|
+
for (const [key, value] of Object.entries(
|
|
55
|
+
manifestJson.chunks
|
|
56
|
+
)) {
|
|
57
|
+
const asset = assets[value.js];
|
|
58
|
+
if (!asset) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const source = new RawSource(
|
|
62
|
+
`import.meta.chunkName = import.meta.chunkName ?? ${JSON.stringify(key)};
|
|
63
|
+
${asset.source()}`
|
|
64
|
+
);
|
|
65
|
+
compilation.updateAsset(value.js, source);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function transFileName(fileName) {
|
|
75
|
+
return fileName.replace(/^.\//, "");
|
|
76
|
+
}
|
|
77
|
+
export function getExports(opts, stats) {
|
|
78
|
+
const entrypoints = stats.entrypoints || {};
|
|
79
|
+
const exports = {};
|
|
80
|
+
for (const [key, value] of Object.entries(entrypoints)) {
|
|
81
|
+
const asset = value.assets?.find((item) => {
|
|
82
|
+
return item.name.endsWith(opts.ext) && item.name.startsWith(key) && !item.name.includes("hot-update");
|
|
83
|
+
});
|
|
84
|
+
if (!asset) continue;
|
|
85
|
+
if (key in opts.exports) {
|
|
86
|
+
exports[key] = {
|
|
87
|
+
...opts.exports[key],
|
|
88
|
+
file: asset.name
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return exports;
|
|
93
|
+
}
|
|
94
|
+
function getChunks(opts, compilation) {
|
|
95
|
+
const stats = compilation.getStats().toJson({
|
|
96
|
+
all: false,
|
|
97
|
+
chunks: true,
|
|
98
|
+
modules: true,
|
|
99
|
+
chunkModules: true,
|
|
100
|
+
ids: true
|
|
101
|
+
});
|
|
102
|
+
const buildChunks = {};
|
|
103
|
+
if (!stats.chunks) return buildChunks;
|
|
104
|
+
for (const chunk of stats.chunks) {
|
|
105
|
+
const module = chunk.modules?.sort((a, b) => {
|
|
106
|
+
return (a.index ?? -1) - (b?.index ?? -1);
|
|
107
|
+
})?.find((module2) => {
|
|
108
|
+
return module2.moduleType?.includes("javascript/");
|
|
109
|
+
});
|
|
110
|
+
if (!module?.nameForCondition) continue;
|
|
111
|
+
const js = chunk.files?.find((file) => file.endsWith(opts.ext));
|
|
112
|
+
if (!js) continue;
|
|
113
|
+
const root = compilation.options.context ?? process.cwd();
|
|
114
|
+
const name = generateIdentifier({
|
|
115
|
+
root,
|
|
116
|
+
name: opts.name,
|
|
117
|
+
filePath: module.nameForCondition
|
|
118
|
+
});
|
|
119
|
+
const css = chunk.files?.filter((file) => file.endsWith(".css")) ?? [];
|
|
120
|
+
const resources = chunk.auxiliaryFiles ?? [];
|
|
121
|
+
buildChunks[name] = {
|
|
122
|
+
name,
|
|
123
|
+
js,
|
|
124
|
+
css,
|
|
125
|
+
resources
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return buildChunks;
|
|
129
|
+
}
|
|
130
|
+
export function generateIdentifier({
|
|
131
|
+
root,
|
|
132
|
+
name,
|
|
133
|
+
filePath
|
|
134
|
+
}) {
|
|
135
|
+
const unixFilePath = upath.toUnix(filePath);
|
|
136
|
+
if (!root) {
|
|
137
|
+
return `${name}@${unixFilePath}`;
|
|
138
|
+
}
|
|
139
|
+
const file = upath.relative(upath.toUnix(root), unixFilePath);
|
|
140
|
+
return `${name}@${file}`;
|
|
141
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function parseOptions(options) {
|
|
2
|
+
const exports = {};
|
|
3
|
+
if (options.exports) {
|
|
4
|
+
for (const [name, item] of Object.entries(options.exports)) {
|
|
5
|
+
exports[name] = {
|
|
6
|
+
name,
|
|
7
|
+
pkg: !!item.pkg,
|
|
8
|
+
file: item.file,
|
|
9
|
+
identifier: `${options.name}/${name}`
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const deps = (options.deps ?? []).filter((name) => name !== options.name);
|
|
14
|
+
return {
|
|
15
|
+
name: options.name,
|
|
16
|
+
ext: options.ext ? `.${options.ext}` : ".mjs",
|
|
17
|
+
exports,
|
|
18
|
+
imports: options.imports ?? {},
|
|
19
|
+
scopes: options.scopes ?? {},
|
|
20
|
+
injectChunkName: options.injectChunkName ?? false,
|
|
21
|
+
preEntries: options.preEntries ?? [],
|
|
22
|
+
deps
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ManifestJsonExports } from '@esmx/core';
|
|
2
|
+
export type { ManifestJson, ManifestJsonChunk, ManifestJsonChunks, ManifestJsonExport, ManifestJsonExports } from '@esmx/core';
|
|
3
|
+
export interface ModuleLinkPluginOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
ext?: string;
|
|
6
|
+
imports?: Record<string, string>;
|
|
7
|
+
scopes?: Record<string, Record<string, string>>;
|
|
8
|
+
exports?: Record<string, {
|
|
9
|
+
pkg?: boolean;
|
|
10
|
+
file: string;
|
|
11
|
+
}>;
|
|
12
|
+
injectChunkName?: boolean;
|
|
13
|
+
preEntries?: string[];
|
|
14
|
+
deps?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface ParsedModuleLinkPluginOptions {
|
|
17
|
+
name: string;
|
|
18
|
+
ext: string;
|
|
19
|
+
exports: ManifestJsonExports;
|
|
20
|
+
imports: Record<string, string>;
|
|
21
|
+
scopes: Record<string, Record<string, string>>;
|
|
22
|
+
injectChunkName: boolean;
|
|
23
|
+
preEntries: string[];
|
|
24
|
+
deps: string[];
|
|
25
|
+
}
|
|
File without changes
|
package/dist/rspack/app.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url";
|
|
2
2
|
import {
|
|
3
|
-
RenderContext,
|
|
4
3
|
createApp,
|
|
5
|
-
mergeMiddlewares
|
|
4
|
+
mergeMiddlewares,
|
|
5
|
+
RenderContext
|
|
6
6
|
} from "@esmx/core";
|
|
7
7
|
import { createVmImport } from "@esmx/import";
|
|
8
8
|
import hotMiddleware from "webpack-hot-middleware";
|
|
@@ -58,14 +58,7 @@ function rewriteRender(esmx) {
|
|
|
58
58
|
const module = await vmImport(
|
|
59
59
|
`${esmx.name}/src/entry.server`,
|
|
60
60
|
import.meta.url,
|
|
61
|
-
|
|
62
|
-
console,
|
|
63
|
-
setTimeout,
|
|
64
|
-
clearTimeout,
|
|
65
|
-
process,
|
|
66
|
-
URL,
|
|
67
|
-
global
|
|
68
|
-
}
|
|
61
|
+
global
|
|
69
62
|
);
|
|
70
63
|
const serverRender = module[rc.entryName];
|
|
71
64
|
if (typeof serverRender === "function") {
|
|
@@ -100,6 +93,8 @@ async function start() {
|
|
|
100
93
|
start();
|
|
101
94
|
`.trim()
|
|
102
95
|
);
|
|
96
|
+
console.log("\n");
|
|
97
|
+
console.log(esmx.generateSizeReport().text);
|
|
103
98
|
return pack(esmx);
|
|
104
99
|
};
|
|
105
100
|
}
|
|
@@ -1,73 +1,80 @@
|
|
|
1
|
-
import {
|
|
2
|
-
moduleLinkPlugin
|
|
3
|
-
} from "@esmx/rspack-module-link-plugin";
|
|
4
1
|
import { rspack } from "@rspack/core";
|
|
5
2
|
import RspackChain from "rspack-chain";
|
|
6
3
|
import nodeExternals from "webpack-node-externals";
|
|
4
|
+
import { initModuleLink } from "../module-link/index.mjs";
|
|
7
5
|
export function createChainConfig(esmx, buildTarget, options) {
|
|
8
6
|
const isHot = buildTarget === "client" && !esmx.isProd;
|
|
9
7
|
const isClient = buildTarget === "client";
|
|
10
8
|
const isServer = buildTarget === "server";
|
|
11
9
|
const isNode = buildTarget === "node";
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const chain = new RspackChain();
|
|
11
|
+
chain.context(esmx.root);
|
|
12
|
+
chain.mode(esmx.isProd ? "production" : "development");
|
|
13
|
+
chain.target(isClient ? "web" : "node24");
|
|
14
|
+
chain.cache(!esmx.isProd);
|
|
15
|
+
chain.output.clean(esmx.isProd).filename(
|
|
18
16
|
!isNode && esmx.isProd ? "[name].[contenthash:8].final.mjs" : "[name].mjs"
|
|
19
17
|
).chunkFilename(
|
|
20
18
|
esmx.isProd ? "chunks/[name].[contenthash:8].final.mjs" : "chunks/[name].mjs"
|
|
21
19
|
).publicPath(
|
|
22
20
|
isClient ? "auto" : `${esmx.basePathPlaceholder}${esmx.basePath}`
|
|
23
21
|
);
|
|
24
|
-
|
|
22
|
+
chain.output.set(
|
|
25
23
|
"cssFilename",
|
|
26
24
|
esmx.isProd ? "[name].[contenthash:8].final.css" : "[name].css"
|
|
27
25
|
);
|
|
28
|
-
|
|
26
|
+
chain.output.set(
|
|
29
27
|
"cssChunkFilename",
|
|
30
28
|
esmx.isProd ? "chunks/[name].[contenthash:8].final.css" : "chunks/[name].css"
|
|
31
29
|
);
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
chain.output.path(esmx.resolvePath("dist", buildTarget));
|
|
31
|
+
chain.plugin("progress").use(rspack.ProgressPlugin, [
|
|
34
32
|
{
|
|
35
33
|
prefix: buildTarget
|
|
36
34
|
}
|
|
37
35
|
]);
|
|
38
|
-
config.plugin("module-link").use(moduleLinkPlugin, [createModuleLinkConfig(esmx, buildTarget)]);
|
|
39
36
|
if (isHot) {
|
|
40
|
-
|
|
37
|
+
chain.plugin("hmr").use(rspack.HotModuleReplacementPlugin);
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
url: isClient ? true : "relative"
|
|
39
|
+
chain.module.parser.set("javascript", {
|
|
40
|
+
url: isClient ? true : "relative",
|
|
41
|
+
importMeta: false,
|
|
42
|
+
strictExportPresence: true
|
|
44
43
|
});
|
|
45
|
-
|
|
44
|
+
chain.module.generator.set("asset", {
|
|
46
45
|
emit: isClient
|
|
47
46
|
});
|
|
48
|
-
|
|
47
|
+
chain.module.generator.set("asset/resource", {
|
|
49
48
|
emit: isClient
|
|
50
49
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
chain.resolve.alias.set(esmx.name, esmx.root);
|
|
51
|
+
chain.optimization.minimize(options.minimize ?? esmx.isProd).emitOnErrors(true);
|
|
52
|
+
chain.externalsPresets({
|
|
54
53
|
web: isClient,
|
|
55
54
|
node: isServer || isNode
|
|
56
55
|
});
|
|
57
|
-
|
|
56
|
+
chain.experiments({
|
|
57
|
+
...chain.get("experiments"),
|
|
58
|
+
outputModule: true
|
|
59
|
+
});
|
|
60
|
+
chain.externalsType("module-import");
|
|
58
61
|
if (isNode) {
|
|
59
|
-
|
|
60
|
-
// @ts-
|
|
62
|
+
chain.externals([
|
|
63
|
+
// @ts-expect-error
|
|
61
64
|
nodeExternals({
|
|
62
|
-
// @ts-
|
|
65
|
+
// @ts-expect-error
|
|
63
66
|
importType: "module-import"
|
|
64
67
|
})
|
|
65
68
|
]);
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
nativeWatcher: true
|
|
70
|
+
chain.experiments({
|
|
71
|
+
nativeWatcher: true,
|
|
72
|
+
rspackFuture: {
|
|
73
|
+
bundlerInfo: { force: false }
|
|
74
|
+
}
|
|
69
75
|
});
|
|
70
|
-
|
|
76
|
+
initModuleLink(chain, createModuleLinkConfig(esmx, buildTarget));
|
|
77
|
+
return chain;
|
|
71
78
|
}
|
|
72
79
|
function createModuleLinkConfig(esmx, buildTarget) {
|
|
73
80
|
const isClient = buildTarget === "client";
|
package/dist/rspack/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { type
|
|
1
|
+
export { createRspackApp, type RspackAppChainContext, type RspackAppConfigContext, type RspackAppOptions } from './app';
|
|
2
2
|
export type { BuildTarget } from './build-target';
|
|
3
3
|
export { RSPACK_LOADER } from './loader';
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "@rspack/core";
|
|
4
4
|
import NodePolyfillPlugin from "node-polyfill-webpack-plugin";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
createRspackApp,
|
|
7
|
+
RSPACK_LOADER
|
|
8
8
|
} from "../rspack/index.mjs";
|
|
9
9
|
import { getTargetSetting } from "./target-setting.mjs";
|
|
10
10
|
export async function createRspackHtmlApp(esmx, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { getTargetSetting, PRESET_TARGETS } from "./target-setting.mjs";
|
|
3
3
|
describe("getTargetSetting", () => {
|
|
4
4
|
const buildTargets = ["client", "server", "node"];
|
|
5
5
|
describe("when setting is undefined", () => {
|
package/package.json
CHANGED
|
@@ -63,8 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@esmx/import": "3.0.0-rc.
|
|
67
|
-
"@esmx/rspack-module-link-plugin": "3.0.0-rc.77",
|
|
66
|
+
"@esmx/import": "3.0.0-rc.79",
|
|
68
67
|
"@npmcli/arborist": "^9.1.6",
|
|
69
68
|
"@rspack/core": "1.6.5",
|
|
70
69
|
"css-loader": "^7.1.2",
|
|
@@ -74,14 +73,15 @@
|
|
|
74
73
|
"rspack-chain": "^1.4.1",
|
|
75
74
|
"style-loader": "^4.0.0",
|
|
76
75
|
"style-resources-loader": "^1.5.0",
|
|
76
|
+
"upath": "^2.0.1",
|
|
77
77
|
"webpack-hot-middleware": "^2.26.1",
|
|
78
78
|
"webpack-node-externals": "~3.0.0",
|
|
79
79
|
"worker-rspack-loader": "^3.1.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@biomejs/biome": "2.3.
|
|
83
|
-
"@esmx/core": "3.0.0-rc.
|
|
84
|
-
"@types/node": "^24.
|
|
82
|
+
"@biomejs/biome": "2.3.7",
|
|
83
|
+
"@esmx/core": "3.0.0-rc.79",
|
|
84
|
+
"@types/node": "^24.0.0",
|
|
85
85
|
"@types/npmcli__arborist": "^6.3.1",
|
|
86
86
|
"@types/pacote": "^11.1.8",
|
|
87
87
|
"@types/webpack-hot-middleware": "^2.25.12",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"unbuild": "3.6.1",
|
|
92
92
|
"vitest": "3.2.4"
|
|
93
93
|
},
|
|
94
|
-
"version": "3.0.0-rc.
|
|
94
|
+
"version": "3.0.0-rc.79",
|
|
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": "29c95da5062140daffe10ba135ba66bae6e65fc6"
|
|
114
114
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export {
|
|
2
|
-
type RspackAppConfigContext,
|
|
3
|
-
type RspackAppChainContext,
|
|
4
|
-
type RspackAppOptions,
|
|
5
2
|
type BuildTarget,
|
|
6
3
|
createRspackApp,
|
|
7
|
-
RSPACK_LOADER
|
|
4
|
+
RSPACK_LOADER,
|
|
5
|
+
type RspackAppChainContext,
|
|
6
|
+
type RspackAppConfigContext,
|
|
7
|
+
type RspackAppOptions
|
|
8
8
|
} from './rspack';
|
|
9
9
|
export { createRspackHtmlApp, type RspackHtmlAppOptions } from './rspack-html';
|
|
10
10
|
|