• Stars
    star
    709
  • Rank 63,849 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build your Typescript Node.js projects using blazing fast esbuild

⚡️ 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

More Repositories

1

react-native-exception-handler

A react native module that lets you to register a global error handler that can capture fatal/non fatal uncaught exceptions.
Objective-C
1,579
star
2

web-push-demo

A blog demo to showcase how push notification works in web
JavaScript
98
star
3

react-native-appstore-version-checker

[Deprecated] A react native module to fetch the version of latest app from android playstore or apple app store
JavaScript
91
star
4

blog-addons-example

Blog: NodeJS Addons Example
C++
84
star
5

react-webcomponentify

Build Web Components with React or Preact (without any extra effort)
TypeScript
68
star
6

blog-docker-dev-environment-example

Example repo for the blog post on docker local development environments
JavaScript
55
star
7

react-native-simple-download-manager

A react native module to schedule downloads on native download manager
Java
36
star
8

ImShow-Java-OpenCV

an alternative to imshow() in C++ OpenCV for Java OpenCV
Java
35
star
9

react-native-exception-handler-example

An example repo showing how to integrate react-native-exception-handler
Objective-C
34
star
10

console-web-ui

Examples to show case how to build web based UI (that can be invoked using curl) for console applications using Javascript(NodeJS)
JavaScript
31
star
11

byemck

A fun goodbye console web service
JavaScript
23
star
12

tar-action

A cross platform github action for using tar. Works on windows, mac and linux
JavaScript
22
star
13

blog-custom-renderer

Custom renderer built as the part of blog post
JavaScript
18
star
14

rn-test-exception-handler

A react native module to purposefully raise a Native Exception to try and crash the app.
Java
18
star
15

basic-node-addon

An example repo to help explain debugging c++ nodejs addons using vscode
C++
14
star
16

undercover

Store your environment variables and secrets in git safely.
JavaScript
14
star
17

use-redux-hook

A simple react hook to get access to redux store
JavaScript
13
star
18

mdview-nodegui

A Markdown editor in NodeGui
TypeScript
12
star
19

blender3js

An Example to show how to do Blender+threeJS+Browserify
JavaScript
12
star
20

openshift-express4

An Example for using Express 4 with Openshift
JavaScript
12
star
21

generator-jspm-es6-quick

yo generator for projects using jspm es6 sass along with optional react or angular or vanilla es6 . Supports live reload . No nonsense . No task runners required. Peace of mind B)
JavaScript
9
star
22

rss-parser-browser

A simple, light-weight RSS parser for browser. Parse strings, URLs and get a JS object back
JavaScript
9
star
23

webcomponents-with-react-webcomponentify

Web components based components library using react-webcomponentify + (P) React. This repo showcases how you can build web components using react without much bundlesize overhead.
HTML
8
star
24

slot-machine

A slot machine game written in pure Javascript and Node JS
JavaScript
8
star
25

rust-module-in-javascript-blog-series

This repo contains the demo code for the blog series in medium
JavaScript
7
star
26

blog-graphql-auth-example

JavaScript
7
star
27

vscode-bigtable

A vscode client for bigtable
TypeScript
6
star
28

DadJokes

A random DadJoke generator app for Mac, Windows and Linux using React NodeGui
TypeScript
5
star
29

webcamaugreality

Augmented Reality Examples using Opencv and OpenGL
C++
4
star
30

a7ul.github.io

A self updating portfolio website of Atul R
TypeScript
4
star
31

TheoryOfFApp

An app that gives no fucks !
JavaScript
3
star
32

teye-jokes

A fun app that returns a random pun
JavaScript
3
star
33

AndroidManager

A complete File Manager cum extra utilities for Andorid on Mac
JavaScript
3
star
34

express4-html-barebone-example

A barebone express4 project example without any templating engine for views
JavaScript
3
star
35

nodegui-karmajs-meetup

Code samples used for NodeGui karmajs meetup demo
HTML
3
star
36

AframeVR-Example

Office space built in WebVR and AFrame - VR for the Web !!!
JavaScript
3
star
37

RN-MultiPlatform

An example repo which demonstrates a single source code base - Android , IOS and web app using react native and react
JavaScript
3
star
38

blog-same-docker-local-prod-example

A code repo for https://blog.atulr.com/docker-local-production-image/
Dockerfile
2
star
39

byeanyfin

A fun farewell console web service
JavaScript
2
star
40

memesearchapp-nodegui-tutorial

A meme search app using Giphy api for NodeGui tutorial at Sitepoint
JavaScript
2
star
41

gitbook-plugin-expo-snack

A gitbook plugin to add expo snacks
JavaScript
2
star
42

VRDemo

Demo VR project in real estate context
JavaScript
1
star
43

ReduxReactExplain

Code that explains how redux and react work
JavaScript
1
star
44

replace-object-content

mutates the source js object and replaces the contents with properties from the passed js object while retaining the source js object reference.
JavaScript
1
star
45

NoFucksGiven

An android app that lets u give no fucks at all ! _|_
Java
1
star
46

secrets.mjs

Manage your team's local environment secrets with gcloud securely.
JavaScript
1
star
47

minion-ladder

Minion Ladder - A snakes and ladders based browser game written in Javascript -
ApacheConf
1
star
48

byeiz

A fun goodbye service for iZettle
JavaScript
1
star
49

electron-react-boilerplate

An electron / web app boiler plate with hot reload and packaging support
JavaScript
1
star
50

react-super-accordion

A hackable super simple accordion that you can customise completely to the core. It can't get more customisable than this.
JavaScript
1
star
51

WaveformPlayer

A next generation modern music player that streams, downloads and plays music from youtube
JavaScript
1
star
52

swish-via-sound-pwa

A POC on how to make swish payment on iZettle Merchant device using Sound!!!
JavaScript
1
star
53

AsteroidsTheGame

Learning Unity by building Asteroids space game.
CSS
1
star