Skip to main content

Create a plugin

Ness 7 plugins use the standard Vite plugin contract. Public official plugins use the @nessframework/* scope; community plugins can use any npm package name.

Vite plugin​

ness-example/index.js
export default function example(options = {}) {
return {
name: 'ness:example',
config() {
return {
resolve: {
alias: { '@example': options.directory || '/src/example' },
},
};
},
};
}

Enable it inside the Ness Vite integration:

ness.config.mjs
import { defineNessConfig } from '@nessframework/router';
import { ness } from '@nessframework/router/vite';
import example from 'ness-example';

export default defineNessConfig({
vite: { plugins: [ness({ plugins: [example()] })] },
});

Plugins can use any Vite hook, including config, transform, generateBundle, configureServer, and handleHotUpdate.

Package exports​

ness-example/package.json
{
"name": "ness-example",
"type": "module",
"exports": {
".": "./src/index.js"
}
}

Migrating a Ness 5 plugin​

Ness 5 and 6 plugins exported an install(config, options) function that mutated a Webpack configuration. That runtime was removed in Ness 7, and install is no longer called.

Rewrite the plugin as a Vite plugin. Most of the mapping is direct:

Ness 5 (install)Vite plugin
config.resolve.aliasreturn { resolve: { alias } } from config()
config.module.rulestransform(code, id)
config.plugins.push(...)a Rollup hook such as generateBundle
config.devServer.headersreturn { server: { headers } } from config()
options.dev / options.envthe environment.command argument to config()