Awesome
viteup
Disclaimer
This software is experimental.
Description
A better (opinionated) way to bundle your TypeScript libraries, powered by Vite + SWC.
- Output format(s) & directory derived from package.json exports & other package.json fields.
- SWC compiler integration with vite-plugin-swc-transform by default
- Zero-to-minimal configuration required, freedom to override
Installation
npm i --save-dev viteup
Note: if you plan on using a different compiler than SWC, you can avoid installing the vite-plugin-swc-transform
dependency:
npm i --save-dev --no-optional viteup
Example Usage
- Add a package.json
exports
or output field to yourpackage.json
file - Add a "build" script to your
package.json
file
{
"name": "my-library",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"build": "viteup"
}
}
Build.
npm run build
Advanced Usage
Examples of package.json
setup for ESM or CommonJS, or both
CommonJS output only for maximum compatibility
{
"name": "my-library",
["type": "commonjs",]
"main": "./dist/index.js",
"scripts": {
"build": "viteup"
}
}
CommonJS output only for "modern module resolution"-capable consumers
{
"name": "my-library",
["type": "commonjs",]
"exports": "./dist/index.js",
"scripts": {
"build": "viteup"
}
}
ESM output only for broad compatibility
{
"name": "my-library",
"module": "./dist/index.mjs",
"scripts": {
"build": "viteup"
}
}
ESM output only for "modern module resolution"-capable consumers
{
"name": "my-library",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"build": "viteup"
}
}
Dual emit CommonJS + ESM output for "modern module resolution"-capable consumers
{
"name": "my-library",
"type": "module",
"exports": {
"require": "./dist/index.cjs",
"default": "./dist/index.js"
},
"scripts": {
"build": "viteup"
}
}
Dual emit CommonJS + ESM output for maximum compatibility
{
"name": "my-library",
["type": "commonjs",]
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
"require": "./dist/index.js",
"default": "./dist/index.mjs"
},
"scripts": {
"build": "viteup"
}
}
Extending or overriding Vite configuration
- FIXME
JavaScript API
- FIXME
Integration with Vitest
- FIXME
Support
Package.json output fields support
- FIXME
Package.json export conditions support
- FIXME