Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
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,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,
},
},
},
]);
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 90,566 weekly downloads. As such, unbuild popularity was classified as popular.
We found that unbuild demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.