Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@common-web/esbuild

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@common-web/esbuild

Using `esbuild` to transpile typescript scripts.

  • 1.0.27
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Common esbuild config

Using esbuild to transpile typescript scripts.

  • Why
  • Requirements
  • Getting Started
  • Running the build
  • Configuration Options
  • Caveats

Why

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:

  • You are creating scripts or servers on node
  • You need to output cjs
  • You need to target es2015 syntax

This 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:

  • You are writing simple node server in typescript you need to transpile to cjs
  • You are writing npm package with utility scripts in typescript you need to transpile to cjs
  • etc...

Requirements

Requires node >= 12.x due to yargs.

Getting started

Install the pkg:

yarn:

yarn add @common-web/esbuild -D

npm:

npm install @common-web/esbuild --save-dev

Running the build

  1. Directly run the cli
// 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

  1. Use the common config file

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

Configuration options

namedescriptiondefaultscli configurabledata type
rootDirworking or root directorycurrent working directoryystring
entryPointentry path for the build (relative to rootDir)./src/index.tsystring
outfileoutput path for the build (relative to rootDir)./dist/index.jsystring
formatformat of the build output'cjs'ystring
platformplatform for the build outputnodeystring
targettarget for the build output'es2015'ystring or string[]
pluginsadditional esbuild plugins[]narray
tsconfigpath to tsconfig./tsconfig.jsonystring
overrideadditional override options on esbuild{}nobject
bundlebundle the filesfalseybolean
externalexternal files to exclude from final bundle[]ystring[]

More options:

Caveats

Please review the esbuild documentation for more options and information.

Examples

Bundling example (full node web app)

FAQs

Package last updated on 18 Apr 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc