npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@common-web/esbuild

v1.0.27

Published

Using `esbuild` to transpile typescript scripts.

Downloads

15

Readme

Common esbuild config

Using esbuild to transpile typescript scripts.

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

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

Caveats

Please review the esbuild documentation for more options and information.

Examples

Bundling example (full node web app)