Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
ardeora committed Nov 2, 2023
0 parents commit 279d242
Show file tree
Hide file tree
Showing 9 changed files with 3,693 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
5 changes: 5 additions & 0 deletions README.md
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.
27 changes: 27 additions & 0 deletions entry.js
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}`);
}
});
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function (): import("solid-start/vite").Adapter;
60 changes: 60 additions & 0 deletions index.js
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`);
}
});
}
26 changes: 26 additions & 0 deletions package.json
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"
}
}
Loading

0 comments on commit 279d242

Please sign in to comment.