
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@common-web/esbuild
Advanced tools
Using esbuild
to transpile typescript scripts.
Why not use esbuild
directly ?
You can use it directly but for typescript projects you’d need additional setup like
handling resolution of external node_modules
and other options like format
, target
, platform
.
This might be for you if:
cjs
es2015
syntaxThis package comes with all the configuration on esbuild out of the box to get up and running without going through the docs and figuring out what options are needed.
Typical uses:
typescript
you need to transpile to cjs
typescript
you need to transpile to cjs
Requires node >= 12.x
due to yargs
.
Install the pkg:
yarn:
yarn add @common-web/esbuild -D
npm:
npm install @common-web/esbuild --save-dev
// simple build
npx esbuild-ts
// Change path
npx esbuild-ts --entryPoint=./path-to-my-entry --outfile=./path-to-my-outfile
For more options see below Configuration Options
Creating build.js file:
// build.js
const config = require('@common-web/esbuild');
const esbuild = require('esbuild');
const path = require('path');
// Simple
esbuild.build(config.getBaseConfig())
.then(() => {
console.log('Build finished');
});
// Advanced (optional)
esbuild.build(
config.getBaseConfig({
entryPoint: './my-custom-entry-file',
outfile: './my-custom-out-file',
plugins: [myCustomPlugin()],
// By default it imports tsconfig from your root directory
tsconfig: './path-to-my-ts-config',
rootDir: path.join(process.cwd(), '../../'),
target: 'esnext'
})
).then(() => {
console.log('Build finished');
});
Add scripts to package.json:
{
...,
"scripts": {
"build": "node ./build.js"
}
}
Run the build:
yarn build
name | description | defaults | cli configurable | data type |
---|---|---|---|---|
rootDir | working or root directory | current working directory | y | string |
entryPoint | entry path for the build (relative to rootDir) | ./src/index.ts | y | string |
outfile | output path for the build (relative to rootDir) | ./dist/index.js | y | string |
format | format of the build output | 'cjs' | y | string |
platform | platform for the build output | node | y | string |
target | target for the build output | 'es2015' | y | string or string[] |
plugins | additional esbuild plugins | [] | n | array |
tsconfig | path to tsconfig | ./tsconfig.json | y | string |
override | additional override options on esbuild | {} | n | object |
bundle | bundle the files | false | y | bolean |
external | external files to exclude from final bundle | [] | y | string[] |
More options:
esbuild
)
Please review the esbuild documentation for more options and information.
FAQs
Using `esbuild` to transpile typescript scripts.
We found that @common-web/esbuild demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.