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

esbuild-node-tsc

v2.0.5

Published

Build your Typescript Node.js projects using blazing fast esbuild

Downloads

61,373

Readme

⚡️ esbuild-node-tsc

Build your Typescript Node.js projects using blazing fast esbuild.

Since esbuild can build large typescript node projects in subsecond speeds, this is quite useful for development builds too if you want to stick with tsc for production builds.

Please note this library doesnt do typechecking. For typechecking please continue to use tsc.

Alternatives

Recently, Many alternatives have been released that allow using esbuild with nodejs projects.

You could try these too. They solve the same problem but using require hooks instead.

How does it work?

esbuild-node-tsc reads the tsconfig.json and builds the typescript project using esbuild. esbuild is the fastest typescript builder around. The purpose of this library is to read tsconfig and translate the options to esbuild.

You can also perform custom postbuild and prebuild operations like copying non ts files such as json, graphql files, images,etc to the dist folder or cleaning up build folder.

Installation

npm install --save-dev esbuild esbuild-node-tsc

Usage

npx esbuild-node-tsc

or use the short form.

npx etsc

Additionally, you can add it to your build scripts

{
  "name": "myproject",
  "version": "0.1.0",
  "scripts": {
    "dev": "etsc"
  }
}

Then just run

npm run dev

Live reloading (nodemon ❤️ esbuild-node-tsc)

Since esbuild can build large typescript projects in subsecond speeds you can use this library instead of ts-node-dev or ts-node which usually slow down when project scales.

To achieve live reloading:

npm install --save-dev nodemon esbuild-node-tsc esbuild

Then add the following script to package.json

{
  "name": "myproject",
  "version": "0.1.0",
  "scripts": {
    "dev": "nodemon"
  }
}

And add a nodemon.json

{
  "watch": ["src"],
  "ignore": ["src/**/*.test.ts"],
  "ext": "ts,mjs,js,json,graphql",
  "exec": "etsc && node ./dist/index.js",
  "legacyWatch": true
}

Finally run

npm run dev

Comparison with tsc

v2.0 Migration and Breaking changes 🌱

In v2.0, esbuild-node-tsc no longer has cpy and rimraf preinstalled and doesnt perform any non source file copying automatically. Instead it exposes prebuild and postbuild hooks which can be used to perform custom operations. See the example below for more details.

Optional configuration

By default esbuild-node-tsc should work out of the box for your project since it reads the necessary configuration from your tsconfig.json

But if things are not working as expected you can configure esbuild-node-tsc by adding etsc.config.js along side tsconfig.json.

Example etsc.config.js

module.exports = {
  // Supports all esbuild.build options
  esbuild: {
    minify: false,
    target: "es2015",
  },
  // Prebuild hook
  prebuild: async () => {
    console.log("prebuild");
    const rimraf = (await import("rimraf")).default;
    rimraf.sync("./dist"); // clean up dist folder
  },
  // Postbuild hook
  postbuild: async () => {
    console.log("postbuild");
    const cpy = (await import("cpy")).default;
    await cpy(
      [
        "src/**/*.graphql", // Copy all .graphql files
        "!src/**/*.{tsx,ts,js,jsx}", // Ignore already built files
      ],
      "dist"
    );
  },
};

All of the above fields are optional.

If you want to use different config files for different types of builds you can do so using the param --config. Example:

  "scripts": {
    "build": "etsc --config=etsc.config.build.js"
  }

License

MIT