build(core): fix SSR bundle and node:sqlite resolution in Vite config
This commit is contained in:
1 parent
f2b7ef0056
commit
bf932477dd
1 file changed
+13
-5
@@ -23,9 +23,10 @@ const toPosix = (p: string) => p.replace(/\\/g, '/');
|
|||||||
// `@snowluma/websocket` is bundled — it's an
|
// `@snowluma/websocket` is bundled — it's an
|
||||||
// in-tree TS workspace wrapper that routes its native `.node`
|
// in-tree TS workspace wrapper that routes its native `.node`
|
||||||
// addon through `dist/native/`. Only Node builtins stay external.
|
// addon through `dist/native/`. Only Node builtins stay external.
|
||||||
const external: string[] = [];
|
const isNodeBuiltin = (id: string) =>
|
||||||
|
id.startsWith('node:') ||
|
||||||
const nodeModules = [...builtinModules, ...builtinModules.map((m) => `node:${m}`)].flat();
|
builtinModules.includes(id) ||
|
||||||
|
builtinModules.includes(id.replace(/^node:/, ''));
|
||||||
|
|
||||||
const runtimeSrc = toPosix(runtimeDir);
|
const runtimeSrc = toPosix(runtimeDir);
|
||||||
const nativeSrc = toPosix(nativeDir);
|
const nativeSrc = toPosix(nativeDir);
|
||||||
@@ -115,8 +116,9 @@ const BaseConfig = (source_map: boolean = false) => defineConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
ssr: true,
|
||||||
sourcemap: source_map,
|
sourcemap: source_map,
|
||||||
target: 'esnext',
|
target: 'node22',
|
||||||
minify: false,
|
minify: false,
|
||||||
lib: {
|
lib: {
|
||||||
entry: {
|
entry: {
|
||||||
@@ -126,7 +128,7 @@ const BaseConfig = (source_map: boolean = false) => defineConfig({
|
|||||||
fileName: (_, entryName) => `${entryName}.mjs`
|
fileName: (_, entryName) => `${entryName}.mjs`
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external: [...nodeModules, ...external],
|
external: isNodeBuiltin,
|
||||||
output: {
|
output: {
|
||||||
// better-sqlite3's JS wrapper is pure CJS — its `require('fs')` /
|
// better-sqlite3's JS wrapper is pure CJS — its `require('fs')` /
|
||||||
// `require('path')` / `require('bindings')` calls get inlined into
|
// `require('path')` / `require('bindings')` calls get inlined into
|
||||||
@@ -142,6 +144,9 @@ const BaseConfig = (source_map: boolean = false) => defineConfig({
|
|||||||
// the shim then transparently delegates every inlined CJS require
|
// the shim then transparently delegates every inlined CJS require
|
||||||
// to the real CJS loader. Node 18+ ships `createRequire` in the
|
// to the real CJS loader. Node 18+ ships `createRequire` in the
|
||||||
// `node:module` builtin, so this is supported on every target.
|
// `node:module` builtin, so this is supported on every target.
|
||||||
|
entryFileNames: '[name].mjs',
|
||||||
|
chunkFileNames: '[name].mjs',
|
||||||
|
|
||||||
banner: [
|
banner: [
|
||||||
"import { createRequire as __snowlumaCreateRequire } from 'node:module';",
|
"import { createRequire as __snowlumaCreateRequire } from 'node:module';",
|
||||||
"const require = __snowlumaCreateRequire(import.meta.url);",
|
"const require = __snowlumaCreateRequire(import.meta.url);",
|
||||||
@@ -153,6 +158,9 @@ const BaseConfig = (source_map: boolean = false) => defineConfig({
|
|||||||
// Required since outDir is outside the vite project root.
|
// Required since outDir is outside the vite project root.
|
||||||
emptyOutDir: true
|
emptyOutDir: true
|
||||||
},
|
},
|
||||||
|
ssr: {
|
||||||
|
noExternal: true,
|
||||||
|
},
|
||||||
define: {
|
define: {
|
||||||
__BUILD_WEBUI__: process.env.BUILD_WEBUI === 'true',
|
__BUILD_WEBUI__: process.env.BUILD_WEBUI === 'true',
|
||||||
__APP_VERSION__: JSON.stringify(rootPkg.version)
|
__APP_VERSION__: JSON.stringify(rootPkg.version)
|
||||||
|
|||||||
Reference in new issue
Block a user