dinou 9.3.0 → 10.0.1

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.
Files changed (166) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/README.md +157 -132
  3. package/dinou/adapters/bun.js +34 -5
  4. package/dinou/adapters/cloudflare.js +110 -17
  5. package/dinou/adapters/deno.js +46 -8
  6. package/dinou/adapters/netlify.js +86 -50
  7. package/dinou/adapters/node.js +8 -0
  8. package/dinou/assets.d.ts +32 -5
  9. package/dinou/bun/build.js +190 -106
  10. package/dinou/cli.js +992 -532
  11. package/dinou/cloudflare/build.js +187 -106
  12. package/dinou/compiled/autoprefixer/index.js +509 -517
  13. package/dinou/compiled/babel-core/index.js +738 -716
  14. package/dinou/compiled/babel-generator/index.js +341 -299
  15. package/dinou/compiled/babel-loader/index.js +766 -744
  16. package/dinou/compiled/babel-parser/index.js +2 -2
  17. package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
  18. package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
  19. package/dinou/compiled/babel-preset-react/index.js +752 -730
  20. package/dinou/compiled/babel-preset-typescript/index.js +738 -716
  21. package/dinou/compiled/babel-traverse/index.js +463 -433
  22. package/dinou/compiled/babel-types/index.js +176 -176
  23. package/dinou/compiled/chokidar/index.js +4 -4
  24. package/dinou/compiled/commander/index.js +15 -15
  25. package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
  26. package/dinou/compiled/css-loader/index.js +289 -289
  27. package/dinou/compiled/css-loader/runtime/api.js +85 -0
  28. package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
  29. package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
  30. package/dinou/compiled/css-loader/runtime/package.json +3 -0
  31. package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
  32. package/dinou/compiled/fast-glob/index.js +5810 -0
  33. package/dinou/compiled/generic-names/index.js +16 -16
  34. package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
  35. package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
  36. package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
  37. package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
  38. package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
  39. package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
  40. package/dinou/compiled/postcss/index.js +83 -83
  41. package/dinou/compiled/postcss-import/index.js +147 -117
  42. package/dinou/compiled/postcss-modules/index.js +216 -216
  43. package/dinou/compiled/resolve/index.js +1224 -0
  44. package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
  45. package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
  46. package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
  47. package/dinou/compiled/rollup-plugin-json/index.js +22 -18
  48. package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
  49. package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
  50. package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
  51. package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
  52. package/dinou/compiled/vendors-manifest.json +59 -83
  53. package/dinou/core/asset-extensions.js +482 -33
  54. package/dinou/core/bailout-proxy.js +21 -2
  55. package/dinou/core/build-static-pages.js +523 -371
  56. package/dinou/core/builtin-asset-extensions.js +63 -0
  57. package/dinou/core/cache-revalidate.js +449 -256
  58. package/dinou/core/cache-slot.js +289 -79
  59. package/dinou/core/client-webpack.jsx +470 -39
  60. package/dinou/core/client.jsx +402 -39
  61. package/dinou/core/config.js +3 -0
  62. package/dinou/core/copy-static-dirs.js +98 -0
  63. package/dinou/core/createScopedName.js +22 -4
  64. package/dinou/core/dinou-paths.js +1 -1
  65. package/dinou/core/discover-layouts.js +200 -0
  66. package/dinou/core/edge-ssr.js +1 -1
  67. package/dinou/core/ensure-vendor-mode.js +78 -19
  68. package/dinou/core/env.js +544 -0
  69. package/dinou/core/export-static.js +41 -9
  70. package/dinou/core/generate-route-types.js +989 -95
  71. package/dinou/core/generate-static-rsc.js +5 -6
  72. package/dinou/core/generate-static.js +45 -6
  73. package/dinou/core/get-abs-path-with-ext.js +217 -75
  74. package/dinou/core/get-asset-from-manifest.js +19 -8
  75. package/dinou/core/get-error-jsx.js +4 -5
  76. package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
  77. package/dinou/core/get-jsx.js +220 -53
  78. package/dinou/core/handler.js +1647 -466
  79. package/dinou/core/import-module.js +7 -0
  80. package/dinou/core/layout-functions.js +72 -13
  81. package/dinou/core/link.jsx +34 -6
  82. package/dinou/core/load-dinou-config.js +520 -89
  83. package/dinou/core/manifest-provider.js +4 -14
  84. package/dinou/core/navigation-utils.js +141 -3
  85. package/dinou/core/navigation.js +134 -50
  86. package/dinou/core/node-middleware-runner.js +165 -0
  87. package/dinou/core/postcss-pipeline.js +236 -0
  88. package/dinou/core/ppr-context.js +114 -22
  89. package/dinou/core/ppr-runtime.js +391 -127
  90. package/dinou/core/redirect.jsx +1 -1
  91. package/dinou/core/render-jsx-to-client-jsx.js +216 -48
  92. package/dinou/core/request-context.js +59 -3
  93. package/dinou/core/resolve-contextual-dinou.js +523 -0
  94. package/dinou/core/resolve-setup-files.js +85 -27
  95. package/dinou/core/revalidating.js +10 -2
  96. package/dinou/core/route-generator.js +6 -2
  97. package/dinou/core/rsc-renderer.js +4 -1
  98. package/dinou/core/run-ssg.js +6 -0
  99. package/dinou/core/runtime-env.js +265 -0
  100. package/dinou/core/server-css-modules-plugin.js +155 -0
  101. package/dinou/core/server-function-proxy-webpack.js +27 -2
  102. package/dinou/core/server-function-proxy.js +27 -2
  103. package/dinou/core/slot.js +47 -2
  104. package/dinou/core/static-assets.js +503 -0
  105. package/dinou/core/storage-adapter.js +452 -24
  106. package/dinou/core/transform-server-functions.js +272 -24
  107. package/dinou/core/tsconfig-aliases.js +964 -0
  108. package/dinou/core/uneject.js +640 -0
  109. package/dinou/core/url-resolver.js +1 -1
  110. package/dinou/core/vfs.js +11 -2
  111. package/dinou/css.d.ts +4 -1
  112. package/dinou/deno/build.js +205 -153
  113. package/dinou/deno/seed-kv.js +4 -0
  114. package/dinou/env.d.ts +22 -2
  115. package/dinou/esbuild/build.js +40 -50
  116. package/dinou/esbuild/dev.js +33 -7
  117. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
  118. package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
  119. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
  120. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
  121. package/dinou/esbuild/helpers-esbuild/write.js +13 -3
  122. package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
  123. package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
  124. package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
  125. package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
  126. package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
  127. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
  128. package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
  129. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
  130. package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
  131. package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
  132. package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
  133. package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
  134. package/dinou/index.d.ts +1028 -88
  135. package/dinou/node/build.js +138 -74
  136. package/dinou/node/bundle-dual-engine.js +393 -131
  137. package/dinou/node/dev.js +1005 -275
  138. package/dinou/package.json +11 -34
  139. package/dinou/rollup/postcss.config.js +3 -4
  140. package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
  141. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
  142. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
  143. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
  144. package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
  145. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
  146. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
  147. package/dinou/rollup/rollup.config.js +174 -101
  148. package/dinou/scripts/build-vendors.js +123 -33
  149. package/dinou/server.d.ts +126 -15
  150. package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
  151. package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
  152. package/dinou/webpack/loaders/server-functions-loader.js +1 -1
  153. package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
  154. package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
  155. package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
  156. package/dinou/webpack/postcss.config.js +3 -4
  157. package/dinou/webpack/webpack.config.js +408 -132
  158. package/eject.js +6 -224
  159. package/package.json +7 -9
  160. package/dinou/compiled/cross-env/index.js +0 -661
  161. package/dinou/compiled/dotenv/index.js +0 -375
  162. package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
  163. package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
  164. package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
  165. package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
  166. package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
@@ -1,43 +1,64 @@
1
- import "./helpers/patch-webpack-internals.js";
2
- import "dotenv/config";
1
+ import { loadReactServerWebpackPlugin } from "./helpers/patch-webpack-internals.js";
2
+ import {
3
+ loadEnvFiles,
4
+ getWebpackPublicEnvDefines,
5
+ } from "../core/env.js";
6
+ import { isUnvendorizedRequested } from "../core/ensure-vendor-mode.js";
3
7
  import path from "node:path";
4
8
  import fs from "node:fs";
5
- import { execSync } from "node:child_process";
9
+ import { spawnSync } from "node:child_process";
10
+ import { createRequire } from "node:module";
6
11
  import { fileURLToPath } from "node:url";
7
- import ReactServerWebpackPlugin from "react-server-dom-webpack/plugin";
8
12
  import CopyWebpackPlugin from "#copy-webpack-plugin";
9
13
  import MiniCssExtractPlugin from "#mini-css-extract-plugin";
14
+ import presetReactModule from "#babel/preset-react";
15
+ import presetTypescriptModule from "#babel/preset-typescript";
16
+ import pluginSyntaxImportMetaModule from "#babel/plugin-syntax-import-meta";
17
+ import pluginReactCompilerModule from "#babel-plugin-react-compiler";
18
+ import esbuild from "esbuild";
10
19
  import createScopedName from "../core/createScopedName.js";
11
- import TsconfigPathsPlugin from "#tsconfig-paths-webpack-plugin";
20
+ import {
21
+ createBasePostCssPlugins,
22
+ getRegisteredCssUrlAssets,
23
+ } from "../core/postcss-pipeline.js";
24
+ import {
25
+ hasPublicStylesCss,
26
+ warnPublicStylesCssCollision,
27
+ } from "../core/copy-static-dirs.js";
28
+ import { getDinouConfig } from "../core/load-dinou-config.js";
29
+ import {
30
+ createWebpackTsconfigAliasesResolvePlugin,
31
+ getWatchedTsconfigFiles,
32
+ } from "../core/tsconfig-aliases.js";
12
33
  import manifestGeneratorPlugin from "./plugins/manifest-generator-plugin.js";
13
34
  import ServerFunctionsPlugin from "./plugins/server-functions-plugin.js";
14
35
  import WebpackMemoryPlugin from "./plugins/webpack-memory-plugin.js";
15
36
  import webpack from "webpack";
16
- import { regex } from "../core/asset-extensions.js";
37
+ import {
38
+ getAssetExtensionsInfo,
39
+ getAssetFileName,
40
+ resolveAssetImport,
41
+ } from "../core/asset-extensions.js";
17
42
  import getCSSEntries from "./helpers/get-webpack-entries.js";
18
43
  import {
19
44
  scanProjectDependenciesForClientComponents,
20
45
  scanProjectDependenciesForClientComponentsAsync,
21
46
  } from "../core/scan-dependency-components.js";
22
47
  import { useClientRegex } from "../constants.js";
48
+ import { generateRouteTypes } from "../core/generate-route-types.js";
49
+ import {
50
+ createWebpackUnderscoreDirExclude,
51
+ webpackContextualDinouPlugin,
52
+ } from "../core/resolve-contextual-dinou.js";
23
53
 
24
54
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
25
55
 
26
56
  const isDevelopment = process.env.NODE_ENV !== "production";
57
+ loadEnvFiles(process.cwd(), {
58
+ mode: isDevelopment ? "development" : "production",
59
+ });
27
60
  const outputDirectory = isDevelopment ? ".dinou/public" : ".dinou/dist3";
28
61
 
29
- function getConfigFileIfExists() {
30
- const tsconfigPath = path.resolve(process.cwd(), "tsconfig.json");
31
- const jsconfigPath = path.resolve(process.cwd(), "jsconfig.json");
32
-
33
- if (fs.existsSync(tsconfigPath)) return tsconfigPath;
34
- if (fs.existsSync(jsconfigPath)) return jsconfigPath;
35
-
36
- return null;
37
- }
38
-
39
- const configFile = getConfigFileIfExists();
40
-
41
62
  const localDinouPath = path.resolve(process.cwd(), "dinou");
42
63
  const isEjected = fs.existsSync(localDinouPath);
43
64
 
@@ -51,6 +72,8 @@ const projectRoot = process.cwd();
51
72
 
52
73
  const outputDirs = [
53
74
  path.resolve(projectRoot, ".dinou/public"),
75
+ path.resolve(projectRoot, ".dinou/node-dev"),
76
+ path.resolve(projectRoot, ".dinou/dist1"),
54
77
  path.resolve(projectRoot, ".dinou/dist3"),
55
78
  path.resolve(projectRoot, "out"),
56
79
  path.resolve(projectRoot, "dist"),
@@ -73,6 +96,17 @@ function cleanDir(dir) {
73
96
  }
74
97
 
75
98
  export default async () => {
99
+ const envMode = isDevelopment ? "development" : "production";
100
+ loadEnvFiles(process.cwd(), { mode: envMode });
101
+ const dinouConfig = await getDinouConfig();
102
+ const enableReactCompiler = dinouConfig?.reactCompiler !== false;
103
+ const { regex: activeAssetRegex } = getAssetExtensionsInfo(
104
+ dinouConfig,
105
+ process.cwd()
106
+ );
107
+ try {
108
+ generateRouteTypes(process.cwd());
109
+ } catch (e) {}
76
110
  const outputDir = path.resolve(process.cwd(), outputDirectory);
77
111
 
78
112
  const shouldWriteToDisk =
@@ -81,8 +115,45 @@ export default async () => {
81
115
  // 🔥 CLEAN HARD
82
116
  if (shouldWriteToDisk) {
83
117
  cleanDir(outputDir);
118
+ if (!isDevelopment) {
119
+ cleanDir(path.resolve(process.cwd(), ".dinou/dist1"));
120
+ cleanDir(path.resolve(process.cwd(), ".dinou/netlify"));
121
+ } else {
122
+ const nodeDevDir = path.resolve(process.cwd(), ".dinou/node-dev");
123
+ for (const stale of [
124
+ "react-client-manifest.json",
125
+ "react-ssr-manifest.json",
126
+ "server-functions-manifest.json",
127
+ "manifest.json",
128
+ ]) {
129
+ try {
130
+ fs.rmSync(path.join(nodeDevDir, stale), { force: true });
131
+ } catch (e) {}
132
+ }
133
+ }
84
134
  }
85
- const [cssEntries, , serverFiles] = await getCSSEntries();
135
+ const [cssEntries, , serverFiles, serverAssetEntries] = await getCSSEntries({
136
+ assetInclude: activeAssetRegex,
137
+ dinouConfig,
138
+ });
139
+ const ReactServerWebpackPlugin = loadReactServerWebpackPlugin();
140
+ const dinouReq = createRequire(import.meta.url);
141
+ const projectReq = createRequire(path.resolve(process.cwd(), "package.json"));
142
+ const resolveLoader = (specifier) => {
143
+ try {
144
+ return dinouReq.resolve(specifier);
145
+ } catch {
146
+ return projectReq.resolve(specifier);
147
+ }
148
+ };
149
+ const babelLoaderPath = resolveLoader("#babel-loader");
150
+ const cssLoaderPath = resolveLoader("#css-loader");
151
+ const postcssLoaderPath = resolveLoader("postcss-loader");
152
+ const unwrapBabel = (mod) => mod?.default ?? mod;
153
+ const presetReact = unwrapBabel(presetReactModule);
154
+ const presetTypescript = unwrapBabel(presetTypescriptModule);
155
+ const pluginSyntaxImportMeta = unwrapBabel(pluginSyntaxImportMetaModule);
156
+ const pluginReactCompiler = unwrapBabel(pluginReactCompilerModule);
86
157
 
87
158
  const dependencyClientFiles = new Set();
88
159
  if (typeof scanProjectDependenciesForClientComponentsAsync === "function") {
@@ -99,23 +170,27 @@ export default async () => {
99
170
  );
100
171
  }
101
172
 
102
- let clientDone = false;
103
- let serverDone = false;
104
173
  let ssgExecuted = false;
105
174
 
106
175
  function runPostBuild() {
107
- if (clientDone && serverDone && !ssgExecuted) {
176
+ if (!ssgExecuted) {
108
177
  ssgExecuted = true;
109
- const serverDir = path.resolve(process.cwd(), ".dinou/dist3/server");
110
- fs.mkdirSync(serverDir, { recursive: true });
111
- fs.writeFileSync(
112
- path.join(serverDir, "package.json"),
113
- JSON.stringify({ type: "module" }, null, 2)
114
- );
115
- execSync(`"${process.execPath}" --conditions=react-server "${path.resolve(__dirname, "../core/run-ssg.js")}"`, {
178
+ const ssgArgs = [
179
+ "--conditions=react-server",
180
+ ...(isUnvendorizedRequested() ? ["--conditions=unvendorized"] : []),
181
+ path.resolve(__dirname, "../core/run-ssg.js"),
182
+ ];
183
+ const ssgRes = spawnSync(process.execPath, ssgArgs, {
116
184
  stdio: "inherit",
117
- env: { ...process.env, NODE_ENV: "production", DINOU_BUILD_TOOL: "webpack" },
185
+ env: {
186
+ ...process.env,
187
+ NODE_ENV: "production",
188
+ DINOU_BUILD_TOOL: "webpack",
189
+ },
118
190
  });
191
+ if (ssgRes.status !== 0) {
192
+ throw new Error(`[Dinou SSG] Static generation exited with code ${ssgRes.status ?? 1}`);
193
+ }
119
194
  }
120
195
  }
121
196
  const clientConfig = {
@@ -173,7 +248,11 @@ export default async () => {
173
248
  {
174
249
  test: /\.[jt]sx?$/,
175
250
  type: "javascript/auto",
176
- exclude: [/[\\/]node_modules[\\/](?!dinou)/, ...outputDirs],
251
+ exclude: [
252
+ /[\\/]node_modules[\\/](?!dinou)/,
253
+ /[\\/]dinou[\\/]compiled[\\/]/,
254
+ ...outputDirs,
255
+ ],
177
256
  use: [
178
257
  isDevelopment
179
258
  ? {
@@ -183,15 +262,17 @@ export default async () => {
183
262
  },
184
263
  }
185
264
  : {
186
- loader: "babel-loader",
265
+ loader: babelLoaderPath,
187
266
  options: {
267
+ configFile: false,
268
+ babelrc: false,
188
269
  presets: [
189
- ["@babel/preset-react", { runtime: "automatic" }],
190
- "@babel/preset-typescript",
270
+ [presetReact, { runtime: "automatic" }],
271
+ presetTypescript,
191
272
  ],
192
273
  plugins: [
193
- "babel-plugin-react-compiler",
194
- "@babel/plugin-syntax-import-meta",
274
+ enableReactCompiler && pluginReactCompiler,
275
+ pluginSyntaxImportMeta,
195
276
  ].filter(Boolean),
196
277
  },
197
278
  },
@@ -216,8 +297,12 @@ export default async () => {
216
297
  },
217
298
  },
218
299
  {
219
- loader: "css-loader",
300
+ loader: cssLoaderPath,
220
301
  options: {
302
+ url: {
303
+ filter: (url) => !url.startsWith("/"),
304
+ },
305
+ import: false,
221
306
  modules: {
222
307
  getLocalIdent: (context, localIdentName, localName) => {
223
308
  return createScopedName(localName, context.resourcePath);
@@ -226,7 +311,15 @@ export default async () => {
226
311
  importLoaders: 1,
227
312
  },
228
313
  },
229
- "postcss-loader",
314
+ {
315
+ loader: postcssLoaderPath,
316
+ options: {
317
+ postcssOptions: {
318
+ config: false,
319
+ plugins: createBasePostCssPlugins(),
320
+ },
321
+ },
322
+ },
230
323
  ],
231
324
  },
232
325
  {
@@ -234,40 +327,74 @@ export default async () => {
234
327
  exclude: /\.module\.css$/,
235
328
  use: [
236
329
  MiniCssExtractPlugin.loader,
237
- "css-loader",
238
330
  {
239
- loader: "postcss-loader",
331
+ loader: cssLoaderPath,
332
+ options: {
333
+ url: {
334
+ filter: (url) => !url.startsWith("/"),
335
+ },
336
+ import: false,
337
+ importLoaders: 1,
338
+ },
339
+ },
340
+ {
341
+ loader: postcssLoaderPath,
240
342
  options: {
241
343
  postcssOptions: {
242
- config: path.resolve(__dirname, "postcss.config.js"),
344
+ config: false,
345
+ plugins: createBasePostCssPlugins(),
243
346
  },
244
347
  },
245
348
  },
246
349
  ],
247
350
  },
248
351
  {
249
- test: regex,
352
+ test: activeAssetRegex,
250
353
  type: "asset/resource",
251
354
  generator: {
252
355
  filename: (pathData) => {
253
356
  const resourcePath =
254
- pathData.module.resourceResolveData?.path ||
255
- pathData.module.resource;
256
-
257
- const base = path.basename(
258
- resourcePath,
259
- path.extname(resourcePath),
260
- );
261
- const scoped = createScopedName(base, resourcePath);
262
-
263
- return `/assets/${scoped}[ext]`;
357
+ pathData.module?.resourceResolveData?.path ||
358
+ pathData.module?.resource ||
359
+ pathData.filename;
360
+ return getAssetFileName(resourcePath, process.cwd());
264
361
  },
265
- publicPath: "",
362
+ publicPath: "/",
266
363
  },
267
364
  },
268
365
  ],
269
366
  },
270
367
  plugins: [
368
+ webpackContextualDinouPlugin({ projectRoot: process.cwd() }),
369
+ {
370
+ apply(compiler) {
371
+ compiler.hooks.normalModuleFactory.tap(
372
+ "DinouWebpackAssetAliasPlugin",
373
+ (nmf) => {
374
+ nmf.hooks.beforeResolve.tap(
375
+ "DinouWebpackAssetAliasPlugin",
376
+ (resolveData) => {
377
+ if (!resolveData || !resolveData.request) return;
378
+ const cleanReq = resolveData.request
379
+ .split("?")[0]
380
+ .split("#")[0];
381
+ if (!activeAssetRegex.test(cleanReq)) return;
382
+ const importer = resolveData.contextInfo?.issuer || "";
383
+ const resolved = resolveAssetImport(resolveData.request, {
384
+ importer,
385
+ resolveDir: resolveData.context || process.cwd(),
386
+ projectRoot: process.cwd(),
387
+ assetRegex: activeAssetRegex,
388
+ });
389
+ if (resolved) {
390
+ resolveData.request = resolved;
391
+ }
392
+ }
393
+ );
394
+ }
395
+ );
396
+ },
397
+ },
271
398
  new ReactServerWebpackPlugin({
272
399
  isServer: false,
273
400
  clientReferences: [
@@ -275,6 +402,7 @@ export default async () => {
275
402
  directory: "./src",
276
403
  recursive: true,
277
404
  include: /\.(js|ts|jsx|tsx)$/,
405
+ exclude: createWebpackUnderscoreDirExclude(process.cwd()),
278
406
  },
279
407
  {
280
408
  directory: path.resolve(__dirname, "../core"),
@@ -284,6 +412,68 @@ export default async () => {
284
412
  ...Array.from(dependencyClientFiles),
285
413
  ],
286
414
  }),
415
+ {
416
+ apply(compiler) {
417
+ const pluginName = "DinouRelocateRscManifestsPlugin";
418
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
419
+ const { Compilation } = compiler.webpack || webpack;
420
+ compilation.hooks.processAssets.tap(
421
+ {
422
+ name: pluginName,
423
+ stage: Compilation.PROCESS_ASSETS_STAGE_REPORT + 100,
424
+ },
425
+ () => {
426
+ const clientAsset = compilation.getAsset("react-client-manifest.json");
427
+ if (clientAsset) {
428
+ const rawSource = clientAsset.source.source();
429
+ const jsonText = Buffer.isBuffer(rawSource)
430
+ ? rawSource.toString("utf8")
431
+ : String(rawSource);
432
+ if (typeof globalThis !== "undefined") {
433
+ try {
434
+ globalThis.__DINOU_RAW_CLIENT_MANIFEST__ = JSON.parse(jsonText);
435
+ } catch (e) {}
436
+ }
437
+ if (shouldWriteToDisk) {
438
+ const manifestDir = path.resolve(
439
+ process.cwd(),
440
+ isDevelopment ? ".dinou/node-dev" : ".dinou/dist1"
441
+ );
442
+ fs.mkdirSync(manifestDir, { recursive: true });
443
+ fs.writeFileSync(
444
+ path.join(manifestDir, "react-client-manifest.json"),
445
+ jsonText,
446
+ "utf8"
447
+ );
448
+ }
449
+ compilation.deleteAsset("react-client-manifest.json");
450
+ }
451
+
452
+ const ssrAsset = compilation.getAsset("react-ssr-manifest.json");
453
+ if (ssrAsset) {
454
+ if (shouldWriteToDisk) {
455
+ const rawSsr = ssrAsset.source.source();
456
+ const ssrText = Buffer.isBuffer(rawSsr)
457
+ ? rawSsr.toString("utf8")
458
+ : String(rawSsr);
459
+ const manifestDir = path.resolve(
460
+ process.cwd(),
461
+ isDevelopment ? ".dinou/node-dev" : ".dinou/dist1"
462
+ );
463
+ fs.mkdirSync(manifestDir, { recursive: true });
464
+ fs.writeFileSync(
465
+ path.join(manifestDir, "react-ssr-manifest.json"),
466
+ ssrText,
467
+ "utf8"
468
+ );
469
+ }
470
+ compilation.deleteAsset("react-ssr-manifest.json");
471
+ }
472
+ }
473
+ );
474
+ });
475
+ },
476
+ },
287
477
  isDevelopment && {
288
478
  apply(compiler) {
289
479
  compiler.hooks.thisCompilation.tap(
@@ -313,6 +503,11 @@ export default async () => {
313
503
  if (fs.existsSync(srcDir)) {
314
504
  compilation.contextDependencies.add(srcDir);
315
505
  }
506
+ for (const cfgPath of getWatchedTsconfigFiles(process.cwd())) {
507
+ if (fs.existsSync(cfgPath)) {
508
+ compilation.fileDependencies.add(cfgPath);
509
+ }
510
+ }
316
511
  });
317
512
  },
318
513
  },
@@ -322,11 +517,15 @@ export default async () => {
322
517
  from: "public",
323
518
  to: ".",
324
519
  noErrorOnMissing: true,
325
- },
326
- {
327
- from: "favicons",
328
- to: ".",
329
- noErrorOnMissing: true,
520
+ globOptions: {
521
+ dot: true,
522
+ ignore: [
523
+ "**/.DS_Store",
524
+ "**/Thumbs.db",
525
+ "**/.env",
526
+ "**/.env.*",
527
+ ],
528
+ },
330
529
  },
331
530
  ],
332
531
  }),
@@ -345,39 +544,175 @@ export default async () => {
345
544
  manifest: manifestGeneratorPlugin.manifestData,
346
545
  serverFiles,
347
546
  }),
547
+ new webpack.DefinePlugin(
548
+ getWebpackPublicEnvDefines({
549
+ mode: envMode,
550
+ extra: isDevelopment
551
+ ? {
552
+ DINOU_HMR_PORT: String(
553
+ process.env.HMR_PORT || Number(process.env.PORT || 3000) + 1
554
+ ),
555
+ }
556
+ : undefined,
557
+ })
558
+ ),
559
+ {
560
+ apply(compiler) {
561
+ const pluginName = "DinouCssAssetsAndMinifyPlugin";
562
+ const clearRegistry = () => {
563
+ getRegisteredCssUrlAssets().clear();
564
+ if (typeof globalThis !== "undefined") {
565
+ globalThis.__DINOU_HAS_COMPILED_STYLES__ = false;
566
+ }
567
+ };
568
+ compiler.hooks.run.tap(pluginName, clearRegistry);
569
+ compiler.hooks.watchRun.tap(pluginName, clearRegistry);
570
+
571
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
572
+ compilation.hooks.processAssets.tap(
573
+ {
574
+ name: pluginName,
575
+ stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
576
+ },
577
+ () => {
578
+ const stylesAsset = compilation.getAsset("styles.css");
579
+ const hasCompiledStyles = Boolean(
580
+ stylesAsset && !stylesAsset.info?.copied
581
+ );
582
+ if (typeof globalThis !== "undefined") {
583
+ globalThis.__DINOU_HAS_COMPILED_STYLES__ = hasCompiledStyles;
584
+ }
585
+ if (hasCompiledStyles) {
586
+ if (hasPublicStylesCss(process.cwd())) {
587
+ warnPublicStylesCssCollision(process.cwd());
588
+ }
589
+ for (const assetObj of compilation.getAssets()) {
590
+ if (
591
+ assetObj.info?.copied &&
592
+ assetObj.name.toLowerCase() === "styles.css"
593
+ ) {
594
+ compilation.deleteAsset(assetObj.name);
595
+ }
596
+ }
597
+ }
598
+
599
+ for (const [
600
+ assetFileName,
601
+ absAssetPath,
602
+ ] of getRegisteredCssUrlAssets().entries()) {
603
+ if (fs.existsSync(absAssetPath)) {
604
+ compilation.fileDependencies.add(absAssetPath);
605
+ if (
606
+ !compilation.getAsset(assetFileName) &&
607
+ !compilation.getAsset("/" + assetFileName)
608
+ ) {
609
+ try {
610
+ const buf = fs.readFileSync(absAssetPath);
611
+ compilation.emitAsset(
612
+ assetFileName,
613
+ new webpack.sources.RawSource(buf)
614
+ );
615
+ } catch (e) {}
616
+ }
617
+ }
618
+ }
619
+
620
+ if (serverAssetEntries && serverAssetEntries.size > 0) {
621
+ for (const assetEntry of serverAssetEntries) {
622
+ const absAssetPath = assetEntry.absPath;
623
+ if (!absAssetPath || !fs.existsSync(absAssetPath)) continue;
624
+ compilation.fileDependencies.add(absAssetPath);
625
+ const assetFileName = getAssetFileName(
626
+ absAssetPath,
627
+ process.cwd()
628
+ );
629
+ if (
630
+ !compilation.getAsset(assetFileName) &&
631
+ !compilation.getAsset("/" + assetFileName)
632
+ ) {
633
+ try {
634
+ const buf = fs.readFileSync(absAssetPath);
635
+ compilation.emitAsset(
636
+ assetFileName,
637
+ new webpack.sources.RawSource(buf)
638
+ );
639
+ } catch (e) {}
640
+ }
641
+ }
642
+ }
643
+ }
644
+ );
645
+
646
+ if (!isDevelopment) {
647
+ compilation.hooks.processAssets.tap(
648
+ {
649
+ name: `${pluginName}:minify`,
650
+ stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
651
+ },
652
+ () => {
653
+ const cssAsset = compilation.getAsset("styles.css");
654
+ if (!cssAsset || cssAsset.info?.copied) return;
655
+ try {
656
+ const raw = cssAsset.source.source();
657
+ const rawCss = Buffer.isBuffer(raw)
658
+ ? raw.toString("utf8")
659
+ : String(raw || "");
660
+ if (rawCss) {
661
+ const minified = esbuild.transformSync(rawCss, {
662
+ loader: "css",
663
+ minify: true,
664
+ }).code;
665
+ compilation.updateAsset(
666
+ "styles.css",
667
+ new webpack.sources.RawSource(minified)
668
+ );
669
+ }
670
+ } catch (e) {}
671
+ }
672
+ );
673
+ }
674
+ });
675
+ },
676
+ },
348
677
  isDevelopment && new WebpackMemoryPlugin(),
349
678
  !isDevelopment && {
350
679
  apply(compiler) {
351
- compiler.hooks.done.tap("PostBuildClient", () => {
352
- clientDone = true;
680
+ compiler.hooks.done.tap("PostBuildClient", (stats) => {
681
+ if (stats.hasErrors()) return;
353
682
  runPostBuild();
354
683
  });
355
684
  },
356
685
  },
357
686
  ].filter(Boolean),
358
687
  resolve: {
359
- extensions: [".js", ".jsx", ".ts", ".tsx"],
688
+ conditionNames: ["style", "import", "module", "browser", "default"],
689
+ extensions: [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".json", ".css"],
360
690
  modules: ["src", "node_modules"],
361
691
  extensionAlias: {
362
692
  ".js": [".js", ".ts", ".tsx"],
363
693
  ".jsx": [".jsx", ".tsx"],
694
+ ".mjs": [".mjs", ".mts"],
695
+ ".cjs": [".cjs", ".cts"],
364
696
  },
365
697
  // 🎯 ADD THIS:
366
698
  alias: {
367
- ...(isEjected ? { dinou: localDinouPath } : {}),
699
+ ...(isEjected
700
+ ? {
701
+ "dinou/config": path.join(localDinouPath, "core/config.js"),
702
+ "dinou/server": path.join(localDinouPath, "server.js"),
703
+ dinou: localDinouPath,
704
+ }
705
+ : {}),
368
706
  },
369
707
  fallback: {
370
708
  async_hooks: false,
371
709
  "node:async_hooks": false,
372
710
  },
373
- plugins: configFile
374
- ? [
375
- new TsconfigPathsPlugin({
376
- configFile,
377
- extensions: [".js", ".jsx", ".ts", ".tsx"],
378
- }),
379
- ]
380
- : [],
711
+ plugins: [
712
+ createWebpackTsconfigAliasesResolvePlugin({
713
+ projectRoot: process.cwd(),
714
+ }),
715
+ ],
381
716
  },
382
717
  optimization: {
383
718
  // 2. RUNTIME CHUNK: Vital for sharing module state between entry points
@@ -420,6 +755,8 @@ export default async () => {
420
755
  "**/.git/**",
421
756
  "**/.dinou/node-dev/**",
422
757
  "**/.dinou/dist2/**",
758
+ "**/.dinou/routes/**",
759
+ "**/.dinou/types/**",
423
760
  ...outputDirs.map((dir) => `${dir}/**`),
424
761
  ],
425
762
  },
@@ -454,66 +791,5 @@ export default async () => {
454
791
  : {}),
455
792
  };
456
793
 
457
- if (isDevelopment) {
458
- return clientConfig;
459
- }
460
-
461
- const serverConfig = {
462
- mode: "production",
463
- target: "node20",
464
- experiments: {
465
- outputModule: true,
466
- },
467
- entry: {
468
- handler: path.resolve(__dirname, "../core/handler.js"),
469
- netlify: path.resolve(__dirname, "../adapters/netlify.js"),
470
- },
471
- output: {
472
- path: path.resolve(process.cwd(), outputDirectory, "server"),
473
- filename: "[name].js",
474
- library: {
475
- type: "module",
476
- },
477
- chunkFormat: "module",
478
- },
479
- resolve: {
480
- conditionNames: ["react-server", "node", "import", "require"],
481
- extensions: [".js", ".jsx", ".ts", ".tsx"],
482
- alias: {
483
- ...(isEjected ? { dinou: localDinouPath } : {}),
484
- },
485
- },
486
- externals: [
487
- "express",
488
- "chokidar",
489
- "dotenv",
490
- "fsevents",
491
- "@swc/core",
492
- "@babel/core",
493
- "esbuild",
494
- ],
495
- module: {
496
- exprContextCritical: false,
497
- },
498
- ignoreWarnings: [
499
- /Critical dependency/,
500
- ],
501
- plugins: [
502
- new webpack.BannerPlugin({
503
- banner: "import { createRequire as ___createRequire } from 'node:module'; import { fileURLToPath as ___fileURLToPath } from 'node:url'; import ___path from 'node:path'; const require = ___createRequire(import.meta.url || ___path.resolve(process.cwd(), 'package.json')); globalThis.__dinou_require__ = require; const __filename = import.meta.url ? ___fileURLToPath(import.meta.url) : ___path.resolve(process.cwd(), 'index.js'); const __dirname = ___path.dirname(__filename); process.env.NODE_ENV = process.env.NODE_ENV || 'production';",
504
- raw: true,
505
- entryOnly: false,
506
- }),
507
- {
508
- apply(compiler) {
509
- compiler.hooks.done.tap("PostBuildServer", () => {
510
- serverDone = true;
511
- runPostBuild();
512
- });
513
- },
514
- },
515
- ],
516
- };
517
-
518
- return [clientConfig, serverConfig];
794
+ return clientConfig;
519
795
  };