-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
23 changed files
with
551 additions
and
66 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
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
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
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,4 @@ | ||
{ | ||
"installDependencies": true, | ||
"startCommand": "npm run dev" | ||
} |
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,18 @@ | ||
import express from "express"; | ||
import httpDevServer from "vavite/http-dev-server"; | ||
|
||
const app = express(); | ||
|
||
app.get("/foo", (req, res) => { | ||
console.log("Here"); | ||
res.send("foo"); | ||
}); | ||
|
||
export default app; | ||
|
||
if (httpDevServer) { | ||
httpDevServer.on("request", app); | ||
} else { | ||
console.log("Starting prod server"); | ||
app.listen(3000); | ||
} |
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,21 @@ | ||
{ | ||
"name": "@vavite/example-with-loader", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"start": "node dist", | ||
"dev": "vite", | ||
"build": "vite build --ssr --mode=production" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.14", | ||
"@types/node": "^18.11.14", | ||
"@vavite/node-loader": "1.5.2", | ||
"typescript": "^4.9.4", | ||
"vavite": "1.5.2", | ||
"vite": "^4.0.1" | ||
}, | ||
"dependencies": { | ||
"express": "^4.18.2" | ||
} | ||
} |
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,16 @@ | ||
# Vavite Simple Standalone example | ||
|
||
Simplest example that specifies a `handlerEntry` and handles incoming requests. | ||
|
||
> [Try on StackBlitz](https://stackblitz.com/github/cyco130/vavite/tree/main/examples/simple-standalone) | ||
Clone with: | ||
|
||
```bash | ||
npx degit cyco130/vavite/examples/simple-standalone | ||
``` | ||
|
||
> All examples have `"type": "module"` in their `package.json`. | ||
> | ||
> - For Vite v2, remove it to use CommonJS (CJS). | ||
> - If you want to use CommonJS with Vite v3, add `legacy.buildSsrCjsExternalHeuristics: true` to your Vite config. |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"moduleResolution": "Node" | ||
} | ||
} |
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,13 @@ | ||
import { defineConfig, ViteDevServer } from "vite"; | ||
import { nodeLoaderPlugin } from "@vavite/node-loader/plugin"; | ||
import vavite from "vavite"; | ||
|
||
declare global { | ||
// eslint-disable-next-line no-var | ||
var __vite_dev_server__: ViteDevServer | undefined; | ||
} | ||
|
||
export default defineConfig({ | ||
appType: "custom", | ||
plugins: [nodeLoaderPlugin(), vavite({ serverEntry: "entry-node.ts" })], | ||
}); |
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
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,6 @@ | ||
require("@cyco130/eslint-config/patch"); | ||
|
||
module.exports = { | ||
extends: ["@cyco130/eslint-config/node"], | ||
parserOptions: { tsconfigRootDir: __dirname }, | ||
}; |
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,7 @@ | ||
export default { | ||
"**/*.ts?(x)": [ | ||
() => "tsc -p tsconfig.json --noEmit", | ||
"eslint --max-warnings 0 --ignore-pattern dist", | ||
], | ||
"*": "prettier --ignore-unknown --write", | ||
}; |
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,48 @@ | ||
{ | ||
"name": "@vavite/node-loader", | ||
"version": "1.5.2", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./plugin": { | ||
"import": "./dist/plugin.js", | ||
"require": "./dist/plugin.cjs" | ||
}, | ||
"./suppress-warnings": "./dist/suppress-warnings.cjs" | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"dist/*.d.ts" | ||
] | ||
} | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"description": "ESM loader for transpiling modules with Vite", | ||
"author": "Fatih Aygün <[email protected]>", | ||
"repository": "https://github.com/cyco130/vavite", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch", | ||
"prepack": "rm -rf dist && pnpm build", | ||
"test": "pnpm run test:typecheck && pnpm run test:lint && pnpm run test:package", | ||
"test:typecheck": "tsc -p tsconfig.json --noEmit", | ||
"test:lint": "eslint . --max-warnings 0 --ignore-pattern dist", | ||
"test:package": "publint" | ||
}, | ||
"peerDependencies": { | ||
"vite": ">=2.8.1" | ||
}, | ||
"devDependencies": { | ||
"@cyco130/eslint-config": "^2.1.2", | ||
"eslint": "^8.29.0", | ||
"sirv": "^2.0.2", | ||
"tsup": "^6.5.0", | ||
"typescript": "^4.9.4", | ||
"vite": "^4.0.1", | ||
"@types/node": "^18.11.14" | ||
} | ||
} |
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,29 @@ | ||
# @vavite/node-loader | ||
|
||
`@vavite/node-loader` is [Node ESM loader](https://nodejs.org/api/esm.html#loaders) that uses [Vite](https://vitejs.dev) to transpile modules. It is part of the `vavite` project but it can be used in any Vite SSR project to enable sourcemap and breakpoints support. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install --save-dev @vavite/node-loader | ||
``` | ||
|
||
## Usage | ||
|
||
Add the following to your Vite config: | ||
|
||
```ts | ||
import { defineConfig } from "vite"; | ||
import { nodeLoader } from "@vavite/node-loader/plugin"; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
nodeLoader(), | ||
// ... | ||
], | ||
}); | ||
``` | ||
|
||
And run your project with `node --experimental-loader @vavite/node-loader my-server-entry.js`. | ||
|
||
You can add the `-r @vavite/node-loader/suppress-warning` before the loader option to suppress the warning about experimental loader. |
Oops, something went wrong.