
Product
Go Support Is Now Generally Available
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
@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.
The npm package @common-web/esbuild receives a total of 9 weekly downloads. As such, @common-web/esbuild popularity was classified as not popular.
We found that @common-web/esbuild demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
Security News
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.