Socket
Socket
Sign inDemoInstall

vite-node

Package Overview
Dependencies
Maintainers
1
Versions
253
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-node - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

cli.d.ts

70

package.json
{
"name": "vite-node",
"version": "0.1.11",
"description": "Vite as Node runtime",
"keywords": [
"vite"
],
"homepage": "https://github.com/antfu/vite-node#readme",
"version": "0.1.12",
"description": "Vite as Node.js runtime",
"homepage": "https://github.com/vitest-dev/vitest#readme",
"bugs": {
"url": "https://github.com/antfu/vite-node/issues"
"url": "https://github.com/vitest-dev/vitest/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/antfu/vite-node.git"
"url": "git+https://github.com/vitest-dev/vitest.git",
"directory": "packages/vite-node"
},

@@ -19,50 +17,52 @@ "funding": "https://github.com/sponsors/antfu",

"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"import": "./index.mjs",
"import": "./dist/index.js",
"types": "./index.d.ts"
},
"./cli": {
"import": "./cli.mjs"
"./client": {
"import": "./dist/client.js",
"types": "./client.d.ts"
},
"./server": {
"import": "./dist/server.js",
"types": "./server.d.ts"
},
"./utils": {
"import": "./dist/utils.js",
"types": "./utils.d.ts"
}
},
"main": "./index.mjs",
"module": "./index.mjs",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./index.d.ts",
"bin": {
"vite-node": "./vite-node.mjs"
"vite-node": "./vite-node.js"
},
"files": [
"dist",
"*.d.ts",
"*.mjs"
],
"dependencies": {
"debug": "^4.3.3",
"kolorist": "^1.5.0",
"kolorist": "^1.5.1",
"minimist": "^1.2.5",
"vite": "^2.6.5"
"mlly": "^0.3.17",
"pathe": "^0.2.0",
"vite": "^2.7.10"
},
"devDependencies": {
"@antfu/eslint-config": "^0.11.1",
"@antfu/ni": "^0.11.0",
"@types/debug": "^4.1.7",
"@types/node": "^16.11.11",
"@vitejs/plugin-vue": "^1.10.1",
"bumpp": "^7.1.1",
"eslint": "^8.3.0",
"esno": "^0.12.1",
"typescript": "^4.5.2",
"uvu": "^0.5.2",
"vue": "^3.2.23"
"@types/minimist": "^1.2.2",
"rollup": "^2.63.0"
},
"engines": {
"node": ">=14.0.0"
"node": ">=14.14.0"
},
"scripts": {
"lint": "eslint \"**/*.{ts,mjs}\"",
"release": "bumpp --commit --push --tag && pnpm publish",
"start": "DEBUG=vite-node:* node cli.mjs",
"test": "node cli.mjs -c test/vite.config.ts --vue test/index.test.mjs"
}
"build": "rimraf dist && rollup -c",
"dev": "rollup -c --watch --watch.include=src/**",
"typecheck": "tsc --noEmit"
},
"readme": "# vite-node\n\n[![NPM version](https://img.shields.io/npm/v/vite-node?color=a1b858&label=)](https://www.npmjs.com/package/vite-node)\n\nVite as Node runtime. The engine powers [Vitest](https://github.com/vitest-dev/vitest).\n\n## Features\n\n- Out-of-box ESM & TypeScript support (possible for more with plugins)\n- Top-level await\n- Vite plugins, resolve, aliasing\n- Respect `vite.config.ts`\n- Shims for `__dirname` and `__filename` in ESM\n- Access to native node modules like `fs`, `path`, etc.\n\n## CLI Usage\n\nRun JS/TS file on Node.js using Vite's resolvers and transformers.\n\n```bash\nnpx vite-node index.ts\n```\n\nOptions:\n\n```bash\nnpx vite-node -h\n```\n\n## Programmatic Usage\n\nIn Vite Node, the server and runner (client) are separated, so you can integrate them in different contexts (workers, cross-process, or remote) if needed. The demo below shows a simple example of having the server and running in the same context\n\n```ts\nimport { createServer } from 'vite'\nimport { ViteNodeServer } from 'vite-node/server'\nimport { ViteNodeRunner } from 'vite-node/client'\n\n// create vite server\nconst server = await createServer()\n// this is need to initialize the plugins\nawait server.pluginContainer.buildStart({})\n\n// create vite-node server\nconst node = new ViteNodeServer(server)\n\n// create vite-node runner\nconst runner = new ViteNodeRunner({\n root: server.config.root,\n base: server.config.base,\n // when having the server and runner in a different context,\n // you will need to handle the communication between them\n // and pass to this function\n fetchModule(id) {\n return node.fetchModule(id)\n },\n})\n\n// execute the file\nawait runner.executeFile('./example.ts')\n\n// close the vite server\nawait server.close()\n```\n\n## Credits\n\nBased on [@pi0](https://github.com/pi0)'s brilliant idea of having a Vite server as the on-demand transforming service for [Nuxt's Vite SSR](https://github.com/nuxt/vite/pull/201).\n\nThanks [@brillout](https://github.com/brillout) for kindly sharing this package name.\n\n## Sponsors\n\n<p align=\"center\">\n <a href=\"https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg\">\n <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>\n </a>\n</p>\n\n## License\n\n[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)\n"
}

@@ -5,9 +5,17 @@ # vite-node

Vite as Node runtime.
Vite as Node runtime. The engine powers [Vitest](https://github.com/vitest-dev/vitest).
> **EXPERIMENTAL**
## Features
- Out-of-box ESM & TypeScript support (possible for more with plugins)
- Top-level await
- Vite plugins, resolve, aliasing
- Respect `vite.config.ts`
- Shims for `__dirname` and `__filename` in ESM
- Access to native node modules like `fs`, `path`, etc.
## Usage
## CLI Usage
Run JS/TS file on Node.js using Vite's resolvers and transformers.
```bash

@@ -23,25 +31,37 @@ npx vite-node index.ts

## Features
## Programmatic Usage
- Out-of-box ESM & TypeScript support (possible for more with plugins)
- Top-level await
- Vite plugins, resolve, aliasing
- Respect `vite.config.ts`
- Shims for `__dirname` and `__filename` in ESM
- Access to native node modules like `fs`, `path`, etc.
- Watch mode (like `nodemon`)
In Vite Node, the server and runner (client) are separated, so you can integrate them in different contexts (workers, cross-process, or remote) if needed. The demo below shows a simple example of having the server and running in the same context
## When NOT to Use
```ts
import { createServer } from 'vite'
import { ViteNodeServer } from 'vite-node/server'
import { ViteNodeRunner } from 'vite-node/client'
- Production, yet - in very early stage, check it later
- Most of the time, when other tools can do that job
- We need to start a Vite server upon each execution, which inevitably introduces some overhead. Only use it when you want the same behavior as Vite or the powerful plugins system (for example, testing components with a Vite-specific setup).
// create vite server
const server = await createServer()
// this is need to initialize the plugins
await server.pluginContainer.buildStart({})
## Why?
// create vite-node server
const node = new ViteNodeServer(server)
It runs Vite's id resolving, module transforming, and most importantly, the powerful plugins system!
// create vite-node runner
const runner = new ViteNodeRunner({
root: server.config.root,
base: server.config.base,
// when having the server and runner in a different context,
// you will need to handle the communication between them
// and pass to this function
fetchModule(id) {
return node.fetchModule(id)
},
})
## How?
// execute the file
await runner.executeFile('./example.ts')
It fires up a Vite dev server, transforms the requests, and runs them in Node.
// close the vite server
await server.close()
```

@@ -48,0 +68,0 @@ ## Credits

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc