
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Unbuild is a unified build system for JavaScript and TypeScript libraries. It simplifies the process of building, bundling, and publishing packages by providing a streamlined configuration and execution environment.
Build JavaScript/TypeScript Libraries
Unbuild provides a simple command to build JavaScript or TypeScript libraries. It handles the compilation and bundling of source files into distributable formats.
unbuild build
Watch Mode
Unbuild offers a development mode that watches for changes in the source files and automatically rebuilds the library. This is useful for rapid development and testing.
unbuild dev
Configuration
Unbuild allows configuration through a JSON or JavaScript file. You can specify entry points, enable TypeScript declaration generation, and customize other build options.
{
"entries": ["src/index"],
"declaration": true
}
Rollup is a module bundler for JavaScript that compiles small pieces of code into something larger and more complex, such as a library or application. Compared to Unbuild, Rollup is more flexible and widely used for bundling, but it requires more configuration and setup.
Webpack is a powerful module bundler for JavaScript applications. It is highly configurable and supports a wide range of plugins and loaders. While Webpack is more feature-rich and versatile than Unbuild, it can be more complex to configure for simple library builds.
Tsup is a TypeScript bundler that focuses on simplicity and speed. It is similar to Unbuild in its ease of use and minimal configuration, but it is specifically optimized for TypeScript projects.
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 unbuild --stub
(powered by 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",
"scripts": {
"build": "unbuild",
"prepack": "unbuild"
},
"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,cjs,mjs,ts,mts,cts,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,
});
Or with multiple builds you can declare an array of configs:
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",
/**
* * `compatible` means "src/index.ts" will generate "dist/index.d.mts", "dist/index.d.cts" and "dist/index.d.ts".
* * `node16` means "src/index.ts" will generate "dist/index.d.mts" and "dist/index.d.cts".
* * `true` is equivalent to `compatible`.
* * `false` will disable declaration generation.
* * `undefined` will auto detect based on "package.json". If "package.json" has "types" field, it will be `"compatible"`, otherwise `false`.
*/
declaration: "compatible",
},
{
name: "minified",
entries: ["./src/index"],
outDir: "build/min",
rollup: {
esbuild: {
minify: true,
},
},
},
]);
In build.config.ts
import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({
rollup: {
esbuild: {
tsconfigRaw: {
compilerOptions: {
experimentalDecorators: true,
},
},
},
},
});
import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({
sourcemap: true,
});
corepack enable
(use npm i -g corepack
for Node.js < 16.10)pnpm install
pnpm dev
FAQs
A unified JavaScript build system
The npm package unbuild receives a total of 178,499 weekly downloads. As such, unbuild popularity was classified as popular.
We found that unbuild demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.