dinou 4.0.8 → 4.0.9
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/CHANGELOG.md +7 -0
- package/dinou/core/build-static-pages.js +37 -40
- package/dinou/core/css-require-hook.js +64 -64
- package/dinou/core/generating-isg.js +2 -3
- package/dinou/core/get-error-jsx.js +1 -3
- package/dinou/core/get-file-path-and-dynamic-params.js +0 -1
- package/dinou/core/get-jsx.js +1 -3
- package/dinou/core/get-ssg-jsx-or-jsx.js +2 -2
- package/dinou/core/render-app-to-html.js +1 -5
- package/dinou/core/render-html.js +23 -26
- package/dinou/core/server-function-proxy-webpack.js +2 -3
- package/dinou/core/server.js +20 -65
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.mjs +0 -1
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.mjs +0 -1
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.mjs +8 -8
- package/dinou/esbuild/helpers-esbuild/write.mjs +6 -6
- package/dinou/esbuild/plugins-esbuild/assets-plugin.mjs +17 -17
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.mjs +11 -11
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.mjs +5 -5
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.mjs +12 -12
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +3 -3
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.mjs +12 -39
- package/dinou/esbuild/react-refresh/react-refresh-runtime.mjs +1 -2
- package/dinou/package.json +1 -2
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +4 -4
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +5 -5
- package/dinou/rollup/rollup.config.js +30 -58
- package/dinou/webpack/helpers/get-webpack-entries.js +7 -31
- package/dinou/webpack/loaders/server-functions-loader.js +4 -5
- package/dinou/webpack/plugins/manifest-generator-plugin.js +6 -6
- package/dinou/webpack/plugins/server-functions-plugin.js +7 -12
- package/dinou/webpack/webpack.config.js +21 -36
- package/package.json +1 -2
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// plugins-esbuild/esm-hmr-plugin.mjs
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
// import * as babelCore from "@babel/core";
|
|
5
|
-
// import { babelConfig } from "./babel-config.js";
|
|
6
4
|
import { transformSync } from "@swc/core";
|
|
7
5
|
import { createServer } from "node:http";
|
|
8
6
|
import { EsmHmrEngine } from "./esm-hmr/server.js";
|
|
@@ -55,21 +53,21 @@ export default function esmHmrPlugin({
|
|
|
55
53
|
|
|
56
54
|
const absNorm = norm(abs);
|
|
57
55
|
|
|
58
|
-
// 1.
|
|
59
|
-
//
|
|
56
|
+
// 1. Check if it is a ROOT Entry (client.jsx or error.tsx)
|
|
57
|
+
// These are the ones saved in 'entryAbsPaths'
|
|
60
58
|
const rootIndex = entryAbsPaths.findIndex(
|
|
61
59
|
(entryPath) => norm(entryPath) === absNorm,
|
|
62
60
|
);
|
|
63
61
|
|
|
64
|
-
//
|
|
62
|
+
// CASE A: It is Main or Error (Roots)
|
|
65
63
|
if (rootIndex !== -1) {
|
|
66
64
|
const source = entrySources[rootIndex];
|
|
67
65
|
if (source) {
|
|
68
66
|
let injectCode = `import { createHotContext } from "/__hmr_client__.js";\n`;
|
|
69
67
|
injectCode += `window.__hotContext = createHotContext;\n`;
|
|
70
68
|
|
|
71
|
-
//
|
|
72
|
-
//
|
|
69
|
+
// IMPORTANT: We return RAW 'source' + injection.
|
|
70
|
+
// Without passing through Babel/SWC to prevent $RefreshSig$ from breaking initialization.
|
|
73
71
|
return {
|
|
74
72
|
contents: injectCode + source,
|
|
75
73
|
loader: "jsx",
|
|
@@ -78,31 +76,16 @@ export default function esmHmrPlugin({
|
|
|
78
76
|
return null;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
// 2.
|
|
82
|
-
// (
|
|
79
|
+
// 2. Check if it is any OTHER Entry Point from the esbuild configuration
|
|
80
|
+
// (Here are your pages, layouts, components...)
|
|
83
81
|
const isAnEntryPoint = Object.values(entryPoints).some(
|
|
84
82
|
(val) => norm(path.resolve(val)) === absNorm,
|
|
85
83
|
);
|
|
86
84
|
|
|
87
|
-
//
|
|
85
|
+
// CASE B: It is a user page or component
|
|
88
86
|
if (isAnEntryPoint) {
|
|
89
|
-
//
|
|
87
|
+
// HERE we DO apply SWC transformation to enable React Fast Refresh
|
|
90
88
|
const source = await fs.readFile(args.path, "utf8");
|
|
91
|
-
|
|
92
|
-
// try {
|
|
93
|
-
// const transformed = babelCore.transformSync(source, {
|
|
94
|
-
// ...babelConfig,
|
|
95
|
-
// filename: abs,
|
|
96
|
-
// }).code;
|
|
97
|
-
|
|
98
|
-
// return {
|
|
99
|
-
// contents: transformed,
|
|
100
|
-
// loader: args.path.endsWith(".tsx") ? "tsx" : "jsx",
|
|
101
|
-
// };
|
|
102
|
-
// } catch (e) {
|
|
103
|
-
// // Si babel falla, fallback al original
|
|
104
|
-
// return null;
|
|
105
|
-
// }
|
|
106
89
|
try {
|
|
107
90
|
const { code } = transformSync(source, {
|
|
108
91
|
filename: abs,
|
|
@@ -133,7 +116,7 @@ export default function esmHmrPlugin({
|
|
|
133
116
|
}
|
|
134
117
|
}
|
|
135
118
|
|
|
136
|
-
//
|
|
119
|
+
// CASE C: It is not an entry point (libraries, internal helpers, node_modules...)
|
|
137
120
|
return null;
|
|
138
121
|
});
|
|
139
122
|
|
|
@@ -209,7 +192,7 @@ export default function esmHmrPlugin({
|
|
|
209
192
|
if (window.__isReactRefreshBoundary && window.__isReactRefreshBoundary(module)) {
|
|
210
193
|
window.__debouncePerformReactRefresh();
|
|
211
194
|
} else {
|
|
212
|
-
// Fallback: full reload
|
|
195
|
+
// Fallback: full reload if it is not a boundary
|
|
213
196
|
import.meta.hot.invalidate();
|
|
214
197
|
}
|
|
215
198
|
});
|
|
@@ -230,7 +213,7 @@ export default function esmHmrPlugin({
|
|
|
230
213
|
// );
|
|
231
214
|
return;
|
|
232
215
|
}
|
|
233
|
-
|
|
216
|
+
|
|
234
217
|
if (changedIds.size === 0) return;
|
|
235
218
|
const bundleFiles = Object.keys(result.metafile.outputs);
|
|
236
219
|
const pendingUpdateUrls = new Set();
|
|
@@ -241,15 +224,8 @@ export default function esmHmrPlugin({
|
|
|
241
224
|
|
|
242
225
|
for (const modulePath of modules) {
|
|
243
226
|
if (changedIds.has(normalizePath(path.resolve(modulePath)))) {
|
|
244
|
-
// console.log("entry_________", fileName);
|
|
245
|
-
// console.log(
|
|
246
|
-
// "dependencyTree",
|
|
247
|
-
// hmrEngine.value.getDependencyTree()
|
|
248
|
-
// );
|
|
249
227
|
const url = "/" + path.relative(outdir, fileName);
|
|
250
|
-
// console.log("url", url);
|
|
251
228
|
const entry = hmrEngine.value.getEntry(url);
|
|
252
|
-
// console.log("entry______:", entry);
|
|
253
229
|
if (entry?.isHmrAccepted) {
|
|
254
230
|
pendingUpdateUrls.add(url);
|
|
255
231
|
} else {
|
|
@@ -260,11 +236,9 @@ export default function esmHmrPlugin({
|
|
|
260
236
|
}
|
|
261
237
|
|
|
262
238
|
if (needsFullReload || pendingUpdateUrls.size === 0) {
|
|
263
|
-
// console.log("Full reload____________");
|
|
264
239
|
hmrEngine.value.broadcastMessage({ type: "reload" });
|
|
265
240
|
} else {
|
|
266
241
|
for (const url of pendingUpdateUrls) {
|
|
267
|
-
// console.log("Updateeeee____________");
|
|
268
242
|
hmrEngine.value.broadcastMessage({ type: "update", url });
|
|
269
243
|
}
|
|
270
244
|
}
|
|
@@ -274,5 +248,4 @@ export default function esmHmrPlugin({
|
|
|
274
248
|
};
|
|
275
249
|
}
|
|
276
250
|
|
|
277
|
-
// === Exporta para usar en dev.mjs ===
|
|
278
251
|
export { esmHmrPlugin };
|
|
@@ -7,9 +7,8 @@ if (
|
|
|
7
7
|
) {
|
|
8
8
|
RefreshRuntime.injectIntoGlobalHook(window);
|
|
9
9
|
|
|
10
|
-
// SETEA EL RUNTIME GLOBAL
|
|
11
10
|
window.__reactRefreshRuntime = RefreshRuntime;
|
|
12
|
-
window.$RefreshReg$ = () => {};
|
|
11
|
+
window.$RefreshReg$ = () => { };
|
|
13
12
|
window.$RefreshSig$ = () => (type) => type;
|
|
14
13
|
window.__REACT_REFRESH_RUNTIME_INSTALLED__ = true;
|
|
15
14
|
|
package/dinou/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dinou-ejected",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.9",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"private": true,
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"@babel/register": "^7.27.1",
|
|
24
24
|
"@babel/traverse": "^7.28.3",
|
|
25
25
|
"@esbuild-plugins/tsconfig-paths": "^0.1.2",
|
|
26
|
-
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.2",
|
|
27
26
|
"@roggc/react-server-dom-esm": "^0.0.0-b061b597-20251212",
|
|
28
27
|
"@rollup/plugin-babel": "^6.0.4",
|
|
29
28
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
@@ -194,18 +194,18 @@ function reactClientManifestPlugin({
|
|
|
194
194
|
absolute: true,
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
// B.
|
|
197
|
+
// B. Extract the entry points from the Rollup configuration
|
|
198
198
|
const inputOption = options.input;
|
|
199
199
|
let entryPoints = [];
|
|
200
200
|
|
|
201
201
|
if (typeof inputOption === "string") {
|
|
202
|
-
//
|
|
202
|
+
// Case 1: input: "src/index.js"
|
|
203
203
|
entryPoints = [inputOption];
|
|
204
204
|
} else if (Array.isArray(inputOption)) {
|
|
205
|
-
//
|
|
205
|
+
// Case 2: input: ["src/a.js", "src/b.js"]
|
|
206
206
|
entryPoints = inputOption;
|
|
207
207
|
} else if (typeof inputOption === "object" && inputOption !== null) {
|
|
208
|
-
//
|
|
208
|
+
// Case 3: input: { main: "src/index.js", other: "src/other.js" }
|
|
209
209
|
entryPoints = Object.values(inputOption);
|
|
210
210
|
}
|
|
211
211
|
const uniqueFiles = new Set([...srcFiles, ...entryPoints]);
|
|
@@ -7,7 +7,7 @@ const { useServerRegex } = require("../../constants.js");
|
|
|
7
7
|
|
|
8
8
|
function serverFunctionsPlugin() {
|
|
9
9
|
const root = process.cwd();
|
|
10
|
-
const serverFunctions = new Map(); //
|
|
10
|
+
const serverFunctions = new Map(); // Collect here: Map<relativePath, Set<exports>>
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
name: "server-functions-proxy",
|
|
@@ -18,11 +18,11 @@ function serverFunctionsPlugin() {
|
|
|
18
18
|
if (exports.length === 0) return null;
|
|
19
19
|
|
|
20
20
|
const relativePath = path.relative(root, id);
|
|
21
|
-
serverFunctions.set(relativePath, new Set(exports)); //
|
|
21
|
+
serverFunctions.set(relativePath, new Set(exports)); // Save exports as a Set for uniqueness
|
|
22
22
|
|
|
23
23
|
const fileUrl = `file:///${relativePath}`;
|
|
24
24
|
|
|
25
|
-
//
|
|
25
|
+
// Generate a module that exports proxies instead of the real code
|
|
26
26
|
let proxyCode = `
|
|
27
27
|
import { createServerFunctionProxy } from "/__SERVER_FUNCTION_PROXY__";
|
|
28
28
|
`;
|
|
@@ -63,13 +63,13 @@ function serverFunctionsPlugin() {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
//
|
|
66
|
+
// Generate manifest: convert Map to a simple object
|
|
67
67
|
const manifestObj = {};
|
|
68
68
|
for (const [relPath, exportsSet] of serverFunctions.entries()) {
|
|
69
69
|
manifestObj[relPath] = Array.from(exportsSet);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
//
|
|
72
|
+
// Write the manifest to the specified folder (e.g. same place as other assets)
|
|
73
73
|
const manifestPath = path.join(
|
|
74
74
|
"server_functions_manifest",
|
|
75
75
|
"server-functions-manifest.json"
|
|
@@ -21,10 +21,6 @@ const isDevelopment = process.env.NODE_ENV !== "production";
|
|
|
21
21
|
const outputDirectory = isDevelopment ? "public" : "dist3";
|
|
22
22
|
|
|
23
23
|
const localDinouPath = path.resolve(process.cwd(), "dinou");
|
|
24
|
-
// const localNavigationPath = path.resolve(
|
|
25
|
-
// process.cwd(),
|
|
26
|
-
// "dinou/core/navigation.js"
|
|
27
|
-
// );
|
|
28
24
|
const isEjected = fs.existsSync(localDinouPath);
|
|
29
25
|
|
|
30
26
|
console.log(
|
|
@@ -33,62 +29,42 @@ console.log(
|
|
|
33
29
|
: "📦 [Dinou] Library Mode detected (Using node_modules)",
|
|
34
30
|
);
|
|
35
31
|
|
|
36
|
-
// ----------------------------------------------------------------------
|
|
37
|
-
// 🛠️ ALIAS MICRO-PLUGIN (Zero Dependencies)
|
|
38
|
-
// ----------------------------------------------------------------------
|
|
39
|
-
function localDinouAlias() {
|
|
40
|
-
return {
|
|
41
|
-
name: "local-dinou-alias",
|
|
42
|
-
resolveId(source) {
|
|
43
|
-
// If "dinou" is imported, return local absolute path
|
|
44
|
-
if (source === "dinou") {
|
|
45
|
-
return localDinouPath;
|
|
46
|
-
}
|
|
47
|
-
// // If "dinou/navigation" is imported, return local absolute path
|
|
48
|
-
// if (source === "dinou/navigation") {
|
|
49
|
-
// return localNavigationPath;
|
|
50
|
-
// }
|
|
51
|
-
return null; // If not dinou, let other plugins resolve
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
32
|
module.exports = async function () {
|
|
57
33
|
const del = (await import("rollup-plugin-delete")).default;
|
|
58
34
|
return {
|
|
59
35
|
input: isDevelopment
|
|
60
36
|
? {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
37
|
+
runtime: path.resolve(
|
|
38
|
+
__dirname,
|
|
39
|
+
"react-refresh/react-refresh-runtime.js",
|
|
40
|
+
),
|
|
41
|
+
refresh: path.resolve(
|
|
42
|
+
__dirname,
|
|
43
|
+
"react-refresh/react-refresh-entry.js",
|
|
44
|
+
),
|
|
45
|
+
main: path.resolve(__dirname, "../core/client.jsx"),
|
|
46
|
+
error: path.resolve(__dirname, "../core/client-error.jsx"),
|
|
47
|
+
serverFunctionProxy: path.resolve(
|
|
48
|
+
__dirname,
|
|
49
|
+
"../core/server-function-proxy.js",
|
|
50
|
+
),
|
|
51
|
+
dinouClientRedirect: path.resolve(
|
|
52
|
+
__dirname,
|
|
53
|
+
"../core/client-redirect.jsx",
|
|
54
|
+
),
|
|
55
|
+
}
|
|
80
56
|
: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
57
|
+
main: path.resolve(__dirname, "../core/client.jsx"),
|
|
58
|
+
error: path.resolve(__dirname, "../core/client-error.jsx"),
|
|
59
|
+
serverFunctionProxy: path.resolve(
|
|
60
|
+
__dirname,
|
|
61
|
+
"../core/server-function-proxy.js",
|
|
62
|
+
),
|
|
63
|
+
dinouClientRedirect: path.resolve(
|
|
64
|
+
__dirname,
|
|
65
|
+
"../core/client-redirect.jsx",
|
|
66
|
+
),
|
|
67
|
+
},
|
|
92
68
|
output: {
|
|
93
69
|
dir: outputDirectory,
|
|
94
70
|
format: "esm",
|
|
@@ -107,10 +83,8 @@ module.exports = async function () {
|
|
|
107
83
|
"/refresh.js",
|
|
108
84
|
"/__hmr_client__.js",
|
|
109
85
|
"/__SERVER_FUNCTION_PROXY__",
|
|
110
|
-
// "dinou",
|
|
111
86
|
],
|
|
112
87
|
plugins: [
|
|
113
|
-
// isEjected && localDinouAlias(),
|
|
114
88
|
del({
|
|
115
89
|
targets: [
|
|
116
90
|
`${outputDirectory}/*`,
|
|
@@ -199,8 +173,6 @@ module.exports = async function () {
|
|
|
199
173
|
if (warning.loc && warning.loc.file.includes("request-context.js")) {
|
|
200
174
|
return;
|
|
201
175
|
}
|
|
202
|
-
// If you want to kill it whenever it appears (safer to avoid noise):
|
|
203
|
-
// return;
|
|
204
176
|
}
|
|
205
177
|
if (
|
|
206
178
|
warning.message.includes(
|
|
@@ -22,8 +22,6 @@ async function getCSSEntries({
|
|
|
22
22
|
} = {}) {
|
|
23
23
|
const detectedClientEntries = new Set();
|
|
24
24
|
const detectedCSSEntries = new Set();
|
|
25
|
-
// const detectedAssetEntries = new Set();
|
|
26
|
-
// const serverModules = new Set();
|
|
27
25
|
|
|
28
26
|
async function getImportsAndAssetsAndCsss(
|
|
29
27
|
code,
|
|
@@ -64,7 +62,7 @@ async function getCSSEntries({
|
|
|
64
62
|
continue;
|
|
65
63
|
}
|
|
66
64
|
|
|
67
|
-
//
|
|
65
|
+
// Read the file ONLY once
|
|
68
66
|
let importedCode;
|
|
69
67
|
try {
|
|
70
68
|
importedCode = readFileSync(absImportPathWithExt, "utf8");
|
|
@@ -77,12 +75,12 @@ async function getCSSEntries({
|
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
if (!isTopLevelClientComponent) {
|
|
80
|
-
//
|
|
78
|
+
// Verify if it is a client component
|
|
81
79
|
const isImportedFileClient = useClientRegex.test(importedCode.trim());
|
|
82
80
|
|
|
83
|
-
//
|
|
81
|
+
// If it is a client component, DO NOT process recursively
|
|
84
82
|
if (isImportedFileClient) {
|
|
85
|
-
continue; //
|
|
83
|
+
continue; // Do not recursively process client components
|
|
86
84
|
}
|
|
87
85
|
} else {
|
|
88
86
|
const isImportedFileServer = useServerRegex.test(importedCode.trim());
|
|
@@ -92,7 +90,7 @@ async function getCSSEntries({
|
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
//
|
|
93
|
+
// For non-client modules, process normally
|
|
96
94
|
if (
|
|
97
95
|
absImportPathWithExt.endsWith(".css") ||
|
|
98
96
|
absImportPathWithExt.endsWith(".scss") ||
|
|
@@ -109,7 +107,7 @@ async function getCSSEntries({
|
|
|
109
107
|
|
|
110
108
|
imports.add(absImportPathWithExt);
|
|
111
109
|
|
|
112
|
-
//
|
|
110
|
+
// Process imports recursively for non-client modules
|
|
113
111
|
try {
|
|
114
112
|
const nested = await getImportsAndAssetsAndCsss(
|
|
115
113
|
importedCode,
|
|
@@ -216,10 +214,6 @@ async function getCSSEntries({
|
|
|
216
214
|
`[react-client-manifest] The file ${normalizedPath} is a page or layout without "use client" directive, but its default export is not an async function.`,
|
|
217
215
|
);
|
|
218
216
|
}
|
|
219
|
-
// serverModules.add({
|
|
220
|
-
// absPath: normalizedPath,
|
|
221
|
-
// name: path.basename(normalizedPath, path.extname(normalizedPath)),
|
|
222
|
-
// });
|
|
223
217
|
try {
|
|
224
218
|
const { csss } = await getImportsAndAssetsAndCsss(code, absPath);
|
|
225
219
|
|
|
@@ -231,16 +225,6 @@ async function getCSSEntries({
|
|
|
231
225
|
})),
|
|
232
226
|
);
|
|
233
227
|
}
|
|
234
|
-
|
|
235
|
-
// const serverComponentRegex = /\.(js|jsx|ts|tsx)$/i;
|
|
236
|
-
// imports.forEach((imp) => {
|
|
237
|
-
// if (serverComponentRegex.test(imp) && !imp.includes("node_modules")) {
|
|
238
|
-
// serverModules.add({
|
|
239
|
-
// absPath: normalizePath(imp),
|
|
240
|
-
// name: path.basename(imp, path.extname(imp)),
|
|
241
|
-
// });
|
|
242
|
-
// }
|
|
243
|
-
// });
|
|
244
228
|
} catch (err) {
|
|
245
229
|
/* ignore */
|
|
246
230
|
}
|
|
@@ -260,15 +244,7 @@ async function getCSSEntries({
|
|
|
260
244
|
dCSSE.outfile = `${outfileName}.js`;
|
|
261
245
|
dCSSE.outfileName = outfileName;
|
|
262
246
|
}
|
|
263
|
-
|
|
264
|
-
// for (const sM of serverModules) {
|
|
265
|
-
// const hash = hashFilePath(sM.absPath);
|
|
266
|
-
// const outfileName = `${sM.name}-${hash}`;
|
|
267
|
-
// sM.outfile = `${outfileName}.js`;
|
|
268
|
-
// sM.outfileName = outfileName;
|
|
269
|
-
// }
|
|
270
|
-
|
|
271
|
-
// console.log("detectedCssEntries", detectedCSSEntries);
|
|
247
|
+
|
|
272
248
|
return [detectedCSSEntries, detectedClientEntries];
|
|
273
249
|
}
|
|
274
250
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// server-functions-loader-simple.js
|
|
2
1
|
const path = require("path");
|
|
3
2
|
const parseExports = require("../../core/parse-exports.js");
|
|
4
3
|
const { useServerRegex } = require("../../constants.js");
|
|
@@ -40,16 +39,16 @@ const loadProxy = new Function('return import("/"+"__SERVER_FUNCTION_PROXY__")')
|
|
|
40
39
|
export default (...args) =>
|
|
41
40
|
loadProxy().then(mod =>
|
|
42
41
|
(mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
key,
|
|
43
|
+
)})(...args)
|
|
45
44
|
);
|
|
46
45
|
`;
|
|
47
46
|
} else {
|
|
48
47
|
proxyCode += `
|
|
49
48
|
export const ${exp} = (...args) =>
|
|
50
49
|
loadProxy().then(mod => (mod.default ?? mod ?? window.__SERVER_FUNCTION_PROXY_LIB__).createServerFunctionProxy(${JSON.stringify(
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
key,
|
|
51
|
+
)})(...args)
|
|
53
52
|
);
|
|
54
53
|
`;
|
|
55
54
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// manifest-generator-plugin.js
|
|
2
2
|
class ManifestGeneratorPlugin {
|
|
3
3
|
constructor() {
|
|
4
|
-
this.manifestData = {}; //
|
|
4
|
+
this.manifestData = {}; // same as in Rollup
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
apply(compiler) {
|
|
@@ -10,26 +10,26 @@ class ManifestGeneratorPlugin {
|
|
|
10
10
|
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
11
11
|
const { Compilation } = compiler.webpack;
|
|
12
12
|
|
|
13
|
-
//
|
|
13
|
+
// Run when all assets are ready
|
|
14
14
|
compilation.hooks.processAssets.tap(
|
|
15
15
|
{
|
|
16
16
|
name: pluginName,
|
|
17
17
|
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT,
|
|
18
18
|
},
|
|
19
19
|
(assets) => {
|
|
20
|
-
//
|
|
20
|
+
// Traverse chunks to generate manifest
|
|
21
21
|
for (const chunk of compilation.chunks) {
|
|
22
|
-
if (!chunk.name) continue; //
|
|
22
|
+
if (!chunk.name) continue; // only chunks with a name
|
|
23
23
|
|
|
24
24
|
for (const file of chunk.files) {
|
|
25
25
|
if (file.endsWith(".js")) {
|
|
26
|
-
const cleanName = chunk.name + ".js"; //
|
|
26
|
+
const cleanName = chunk.name + ".js"; // same as Rollup
|
|
27
27
|
this.manifestData[cleanName] = file; // hashed JS file
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// Emit manifest.json
|
|
33
33
|
const json = JSON.stringify(this.manifestData, null, 2);
|
|
34
34
|
|
|
35
35
|
compilation.emitAsset(
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// webpack-server-functions-plugin-simple.js
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
1
|
const manifestGeneratorPlugin = require("./manifest-generator-plugin");
|
|
5
2
|
|
|
6
3
|
class WebpackServerFunctionsPluginSimple {
|
|
@@ -12,7 +9,7 @@ class WebpackServerFunctionsPluginSimple {
|
|
|
12
9
|
const { webpack } = compiler;
|
|
13
10
|
const { Compilation, sources } = webpack;
|
|
14
11
|
|
|
15
|
-
//
|
|
12
|
+
// Collect files generated by the loader
|
|
16
13
|
compiler.hooks.thisCompilation.tap(
|
|
17
14
|
"WebpackServerFunctionsPluginSimple",
|
|
18
15
|
(compilation) => {
|
|
@@ -22,11 +19,9 @@ class WebpackServerFunctionsPluginSimple {
|
|
|
22
19
|
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT,
|
|
23
20
|
},
|
|
24
21
|
(assets) => {
|
|
25
|
-
// 1.
|
|
22
|
+
// 1. Replace placeholder
|
|
26
23
|
const manifest = manifestGeneratorPlugin.manifestData;
|
|
27
|
-
const hashedPath =
|
|
28
|
-
// "/" +
|
|
29
|
-
manifest["serverFunctionProxy.js"] || "serverFunctionProxy.js";
|
|
24
|
+
const hashedPath = manifest["serverFunctionProxy.js"] || "serverFunctionProxy.js";
|
|
30
25
|
|
|
31
26
|
for (const [filename, asset] of Object.entries(assets)) {
|
|
32
27
|
if (filename.endsWith(".js")) {
|
|
@@ -41,7 +36,7 @@ class WebpackServerFunctionsPluginSimple {
|
|
|
41
36
|
}
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
// 2.
|
|
39
|
+
// 2. Collect all server function files
|
|
45
40
|
const serverFunctionsManifest = {};
|
|
46
41
|
|
|
47
42
|
for (const [filename, asset] of Object.entries(assets)) {
|
|
@@ -54,15 +49,15 @@ class WebpackServerFunctionsPluginSimple {
|
|
|
54
49
|
const entry = JSON.parse(content);
|
|
55
50
|
serverFunctionsManifest[entry.path] = entry.exports;
|
|
56
51
|
|
|
57
|
-
//
|
|
52
|
+
// Delete this temporary file
|
|
58
53
|
delete assets[filename];
|
|
59
54
|
} catch (e) {
|
|
60
|
-
//
|
|
55
|
+
// Ignore parsing errors
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
|
|
65
|
-
// 3.
|
|
60
|
+
// 3. Generate final manifest
|
|
66
61
|
const manifestContent = JSON.stringify(
|
|
67
62
|
serverFunctionsManifest,
|
|
68
63
|
null,
|