-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 279d242
Showing
9 changed files
with
3,693 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# start-node | ||
|
||
Adapter for Solid apps that builds a Node server. | ||
|
||
This is very experimental; the adapter API isn't at all fleshed out, and things will definitely change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { dirname, join } from "path"; | ||
import { createServer } from "solid-start-node/server.js"; | ||
import "solid-start/node/globals.js"; | ||
import { fileURLToPath } from "url"; | ||
import manifest from "../../dist/public/route-manifest.json"; | ||
import handler from "./entry-server.js"; | ||
|
||
const { PORT = 3000 } = process.env; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
const paths = { | ||
assets: join(__dirname, "/public") | ||
}; | ||
|
||
const server = createServer({ | ||
paths, | ||
handler, | ||
env: { manifest }, | ||
}); | ||
|
||
server.listen(PORT, err => { | ||
if (err) { | ||
console.log("error", err); | ||
} else { | ||
console.log(`Listening on port ${PORT}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default function (): import("solid-start/vite").Adapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import common from "@rollup/plugin-commonjs"; | ||
import json from "@rollup/plugin-json"; | ||
import nodeResolve from "@rollup/plugin-node-resolve"; | ||
import { readFileSync, writeFileSync } from "fs"; | ||
import { dirname, join } from "path"; | ||
import { rollup } from "rollup"; | ||
import { createAdapter } from "solid-start/vite"; | ||
import { fileURLToPath, pathToFileURL } from "url"; | ||
|
||
export default function nodeAdapter() { | ||
return createAdapter({ | ||
name: "node", | ||
start: (config, { port }) => { | ||
process.env.PORT = port; | ||
import(pathToFileURL(join(config.root, "dist", "server.js")).toString()); | ||
return `http://localhost:${process.env.PORT}`; | ||
}, | ||
async build(config, builder) { | ||
const ssrExternal = config?.ssr?.external || []; | ||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
if (!config.solidOptions.ssr) { | ||
await builder.spaClient(join(config.root, "dist", "public")); | ||
await builder.server(join(config.root, ".solid", "server")); | ||
} else if (config.solidOptions.experimental.islands) { | ||
await builder.islandsClient(join(config.root, "dist", "public")); | ||
await builder.server(join(config.root, ".solid", "server")); | ||
} else { | ||
await builder.client(join(config.root, "dist", "public")); | ||
await builder.server(join(config.root, ".solid", "server")); | ||
} | ||
|
||
let text = readFileSync(join(__dirname, "entry.js")).toString(); | ||
|
||
writeFileSync(join(config.root, ".solid", "server", "server.js"), text); | ||
|
||
builder.debug(`bundling server with rollup`); | ||
|
||
const bundle = await rollup({ | ||
input: join(config.root, ".solid", "server", "server.js"), | ||
plugins: [ | ||
json(), | ||
nodeResolve({ | ||
preferBuiltins: true, | ||
exportConditions: ["node", "solid"] | ||
}), | ||
common({ strictRequires: true, ...config.build.commonjsOptions }) | ||
], | ||
external: ["stream/web", ...ssrExternal] | ||
}); | ||
// or write the bundle to disk | ||
await bundle.write({ format: "esm", dir: join(config.root, "dist") }); | ||
|
||
// closes the bundle | ||
await bundle.close(); | ||
|
||
builder.debug(`bundling server done`); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "@adeora/solid-start-node", | ||
"version": "0.3.9", | ||
"main": "./index.js", | ||
"type": "module", | ||
"solid": { | ||
"type": "adapter" | ||
}, | ||
"dependencies": { | ||
"@rollup/plugin-commonjs": "^24.1.0", | ||
"@rollup/plugin-json": "^6.0.0", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"compression": "^1.7.4", | ||
"polka": "1.0.0-next.22", | ||
"rollup": "^3.26.2", | ||
"sirv": "^2.0.3", | ||
"terser": "^5.19.0" | ||
}, | ||
"devDependencies": { | ||
"vite": "^4.4.6" | ||
}, | ||
"peerDependencies": { | ||
"solid-start": "^0.3.9", | ||
"vite": "^4.4.6" | ||
} | ||
} |
Oops, something went wrong.