Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 8.0.0
### ⚠️ **Breaking Changes!** ⚠️
- support vite 8.x, in order to align with vite major version, the major version of this plugin is bumped to 8.x.
- `tsCompiler` now defaults to `'vite'` (Vite's Oxc pipeline). `'esbuild'` mode has been removed.
- `outputFormat` no longer supports `amd`, `system`, and `systemjs` (not supported by Rolldown in Vite 8).
### other changes
- migrate internal build config from `build.rollupOptions` to `build.rolldownOptions`.
- when `tsCompiler` is set to `'swc'`, the plugin now disables Vite's Oxc transform with `oxc: false`.

## 7.0.0
- support vite 7.x, in order to align with vite major version, the major version of this plugin is bumped to 7.x as well. rip 6
- add `reloadAppOnFileChange` option, when set to true, the app will be reloaded on file changes.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- Node server HMR! (hot module replacement)
- Support Express, Fastify, Koa and Nest out of the box
- Support Custom Request Adapter
- You can choose to use `esbuild` or `swc` to compile your typescript files
- You can choose to use Vite default compiler (`vite`, powered by Oxc) or `swc` to compile your TypeScript files

## Get started

Expand All @@ -31,6 +31,7 @@
Vite version and package version match table:
| Vite | Plugin |
|--------------|----------------|
| 8.x.x | 8.x.x |
| 7.x.x | 7.x.x |
| 6.x.x | 5.x.x |
| 5.x.x | 4.x.x |
Expand Down Expand Up @@ -71,13 +72,12 @@
// if you want to reload your app on file changes, set this to true, rebounce delay is 500ms
reloadAppOnFileChange: false,

// Optional, default: 'esbuild'
// The TypeScript compiler you want to use
// by default this plugin is using vite default ts compiler which is esbuild
// 'swc' compiler is supported to use as well for frameworks
// like Nestjs (esbuild dont support 'emitDecoratorMetadata' yet)
// Optional, default: 'vite'
// The TypeScript compiler mode you want to use
// 'vite' uses Vite's default transformer pipeline (Oxc)
// 'swc' is supported as an opt-in path (e.g. decorator metadata workflows)
// you need to INSTALL `@swc/core` as dev dependency if you want to use swc
tsCompiler: 'esbuild',
tsCompiler: 'vite',

// Optional, default: {
// jsc: {
Expand Down Expand Up @@ -179,7 +179,7 @@ While frontend development tooling is evolving rapidly in recent years, backend

Vite by design has a middleware mode, which allows us to use it programmatically inside other modules. It's originally made for SSR, so that for each request, vite can load the renderer and render the latest changes you made to your app (<https://vitejs.dev/guide/ssr.html>). This plugin leverages this feature to load and execute your server app entry.

You may ask, isn't super slow, since it re-compiles/reloads the entire app? The answer is NO, because vite is smart. It has a builtin module graph as a cache layer, the graph is built up the first time your app loads. After that, when you update a file, vite will only invalidate that one and its parent modules, so that for next request, only those invalidated modules need to be re-compiled which is super fast thanks to esbuild or swc.
You may ask, isn't super slow, since it re-compiles/reloads the entire app? The answer is NO, because vite is smart. It has a builtin module graph as a cache layer, the graph is built up the first time your app loads. After that, when you update a file, vite will only invalidate that one and its parent modules, so that for next request, only those invalidated modules need to be re-compiled which is super fast thanks to Vite's default transformer pipeline (Oxc) or swc.

## To-Do

Expand Down
3 changes: 1 addition & 2 deletions packages/vite-plugin-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite-plugin-node",
"version": "7.0.0",
"version": "8.0.0",
"description": "Vite plugin to enable your node server HMR",
"author": "Axe",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +32,6 @@
"prebuild": "rimraf dist && npm run lint && cp ../../README.md ./readme.md"
},
"dependencies": {
"@rollup/pluginutils": "^4.1.1",
"chalk": "^4.1.2",
"debounce": "^2.2.0",
"debug": "^4.3.2"
Expand Down
16 changes: 8 additions & 8 deletions packages/vite-plugin-node/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- Node server HMR! (hot module replacement)
- Support Express, Fastify, Koa and Nest out of the box
- Support Custom Request Adapter
- You can choose to use `esbuild` or `swc` to compile your typescript files
- You can choose to use Vite default compiler (`vite`, powered by Oxc) or `swc` to compile your TypeScript files

## Get started

Expand All @@ -31,6 +31,7 @@
Vite version and package version match table:
| Vite | Plugin |
|--------------|----------------|
| 8.x.x | 8.x.x |
| 7.x.x | 7.x.x |
| 6.x.x | 5.x.x |
| 5.x.x | 4.x.x |
Expand Down Expand Up @@ -71,13 +72,12 @@
// if you want to reload your app on file changes, set this to true, rebounce delay is 500ms
reloadAppOnFileChange: false,

// Optional, default: 'esbuild'
// The TypeScript compiler you want to use
// by default this plugin is using vite default ts compiler which is esbuild
// 'swc' compiler is supported to use as well for frameworks
// like Nestjs (esbuild dont support 'emitDecoratorMetadata' yet)
// Optional, default: 'vite'
// The TypeScript compiler mode you want to use
// 'vite' uses Vite's default transformer pipeline (Oxc)
// 'swc' is supported as an opt-in path (e.g. decorator metadata workflows)
// you need to INSTALL `@swc/core` as dev dependency if you want to use swc
tsCompiler: 'esbuild',
tsCompiler: 'vite',

// Optional, default: {
// jsc: {
Expand Down Expand Up @@ -179,7 +179,7 @@ While frontend development tooling is evolving rapidly in recent years, backend

Vite by design has a middleware mode, which allows us to use it programmatically inside other modules. It's originally made for SSR, so that for each request, vite can load the renderer and render the latest changes you made to your app (<https://vitejs.dev/guide/ssr.html>). This plugin leverages this feature to load and execute your server app entry.

You may ask, isn't super slow, since it re-compiles/reloads the entire app? The answer is NO, because vite is smart. It has a builtin module graph as a cache layer, the graph is built up the first time your app loads. After that, when you update a file, vite will only invalidate that one and its parent modules, so that for next request, only those invalidated modules need to be re-compiled which is super fast thanks to esbuild or swc.
You may ask, isn't super slow, since it re-compiles/reloads the entire app? The answer is NO, because vite is smart. It has a builtin module graph as a cache layer, the graph is built up the first time your app loads. After that, when you update a file, vite will only invalidate that one and its parent modules, so that for next request, only those invalidated modules need to be re-compiled which is super fast thanks to Vite's default transformer pipeline (Oxc) or swc.

## To-Do

Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export declare type RequestAdapter<App = any> = (params: RequestAdapterParams<Ap

export declare type RequestAdapterOption = SupportedFrameworks | RequestAdapter;

export declare type SupportedTSCompiler = 'esbuild' | 'swc';
export declare type SupportedTSCompiler = 'vite' | 'swc';

export type InternalModuleFormat = 'amd' | 'cjs' | 'es' | 'iife' | 'system' | 'umd';
export type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module' | 'systemjs';
export type InternalModuleFormat = 'cjs' | 'es' | 'iife' | 'umd';
export type ModuleFormat = InternalModuleFormat | 'commonjs' | 'esm' | 'module';
export interface VitePluginNodeConfig {
appPath: string
adapter: RequestAdapterOption
Expand Down
3 changes: 1 addition & 2 deletions packages/vite-plugin-node/src/rollup-plugin-swc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createFilter } from '@rollup/pluginutils';
import type { Compiler, Options } from '@swc/core';
import type { Plugin } from 'vite';
import { type Plugin, createFilter } from 'vite';
import { cleanUrl } from './utils';

export function RollupPluginSwc(options: Options): Plugin {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite-plugin-node/src/vite-plugin-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function VitePluginNode(cfg: VitePluginNodeConfig): Plugin[] {
appPath: cfg.appPath,
adapter: cfg.adapter,
appName: cfg.appName ?? 'app',
tsCompiler: cfg.tsCompiler ?? 'esbuild',
tsCompiler: cfg.tsCompiler ?? 'vite',
exportName: cfg.exportName ?? 'viteNodeApp',
initAppOnBoot: cfg.initAppOnBoot ?? false,
reloadAppOnFileChange: cfg.reloadAppOnFileChange ?? false,
Expand All @@ -42,7 +42,7 @@ export function VitePluginNode(cfg: VitePluginNodeConfig): Plugin[] {
const plugincConfig: ViteConfig = {
build: {
ssr: config.appPath,
rollupOptions: {
rolldownOptions: {
input: config.appPath,
output: {
format: config.outputFormat,
Expand All @@ -64,7 +64,7 @@ export function VitePluginNode(cfg: VitePluginNodeConfig): Plugin[] {
};

if (config.tsCompiler === 'swc')
plugincConfig.esbuild = false;
plugincConfig.oxc = false;

return plugincConfig;
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"rootDir": "src",
"compilerOptions": {
"skipLibCheck": true,
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"strict": true,
"declaration": true,
"noUnusedLocals": true,
Expand All @@ -12,7 +12,7 @@
// node support table: https://node.green/#ES2020-features-optional-chaining-operator-----
"target": "ES2018",
"outDir": "./dist",
"module": "commonjs",
"module": "NodeNext",
"lib": [
"ESNext",
"dom"
Expand Down
Loading