A unified javascript build system
Robust rollup based bundler that supports typescript and generates commonjs and module formats + type declarations.
Automagically infer build config and entries from package.json
.
Integration with mkdist for generating bundleless dists with file-to-file transpilation.
Stub dist
once using jiti and you can try and link your project without needing to watch and rebuild during development.
Integration with untyped.
Automatically check for various build issues such as potential missing and unused dependencies and fail CI.
CLI output also includes output size and exports for quick inspection.
Create src/index.ts
:
export const log = (...args) => { console.log(...args) }
Update package.json
:
{
"type": "module",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
]
}
Note You can find a more complete example in unjs/template for project setup.
Build with unbuild
:
npx unbuild
Configuration is automatically inferred from fields in package.json
mapped to src/
directory. For more control, continue with next section.
Create build.config.ts
:
export default {
entries: [
'./src/index'
]
}
You can either use unbuild
key in package.json
or build.config.{js,ts,json}
to specify configuration.
See options here.
Example:
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
// If entries is not provided, will be automatically inferred from package.json
entries: [
// default
'./src/index',
// mkdist builder transpiles file-to-file keeping original sources structure
{
builder: 'mkdist',
input: './src/package/components/',
outDir: './build/components'
},
],
// Change outDir, default is 'dist'
outDir: 'build',
// Generates .d.ts declaration file
declaration: true,
})
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev