Coder Social home page Coder Social logo

build.js's Introduction

Really smol build system.

It can:

  1. Include specified files or folders (+ rename them if you want to).
  2. Run your TypeScript compiler.
  3. Run your ESBuild bundler.
  4. Restore NPM packages.
  5. Replace strings in files after build.

How to use

  1. Download latest release.
  2. Place it in your project folder.
  3. Prepend content in it with CONFIG.
  4. Run script using node build.js.
  5. You are done!

CONFIG

CONFIG constant is used to configure your build and keep everything in the single build.js file.

It contains:

  • Resources - strings you want to replace in your distribution.
  • "destination": "your folder where distribution is placed"
  • Includes - files you want to include in your distribution.
  • ESBuild - configuration options for ESBuild bundler.
  • Fancy stuff - Flags if you want to force change some auto settings.
Example CONFIG
const CONFIG = {
  resources: {
    version: "1.0.0"
  },

  destination: "dist",
  includes: ["text.txt", "assets/icon.png"]
  // Or
  // includes: [
  //   ["src/text.txt", "text.txt"],
  //   ["assets/icon-128.png", "icon.png"]
  // ]
  // Or
  // includes: {
  //   configuration1: ["text.txt"],
  //   configuration2: ["icon.png"]
  // }
  // Or
  // includes: {
  //   configuration1: [
  //     ["src/text.txt", "text.txt"]
  //   ],
  //   configuration2: [
  //     ["assets/icon-128.png", "icon.png"]
  //   ]
  // }

  // Maybe ESBuild?
  // esbuild: {
  //   entry: "src/index.ts",
  //   outFile: "index.js"
  // },

  // Also some special flags
  // npm: false
  // typescript: false
};

// The rest of build.js

Resources

You can use resources to replace specified strings in your files:

{
  resources: {
    version: "1.0.0"
  }
}

Will replace all $(VERSION) with 1.0.0 in your distribution files. As you can see, replacement format is $(YOUR_RESOURCE_NAME_UPPERCASE).

You can also replace $(THING) with specified file content. Use file:// format to specify file as a content source:

{
  resources: {
    text: "file://text.txt"
  }
}

Will replace all $(TEXT) with text.txt content.

If file is binary then $(THING) will be replaced with base64 encoded content.

Includes

You can include files using

{
  destination: "dist",
  includes: ["text.txt", "assets/icon.png"]
}

Using this syntax file will be included in destnation folder with path provided to file (like assets/icon.png will be dist/assets/icon.png).

or

{
  destination: "dist",
  includes: [
    ["src/text.txt", "text.txt"],
    ["assets/icon-128.png", "icon.png"]
  ]
}

This will include specified files renaming them and placing in folder you specified.

or

{
  destination: "dist",
  includes: {
    configuration1: ["text.txt"],
    configuration2: ["icon.png"]
  }
}

This will include files for selected build configuration.

or

{
  destination: "dist",
  includes: {
    configuration1: [
      ["src/text.txt", "text.txt"]
    ],
    configuration2: [
      ["assets/icon-128.png", "icon.png"]
    ]
  }
}

This will include files for selected build configuration renaming and copying them into directory you specified.

Build configurations

As mentioned before, configurations are used for includes (and maybe will be used for more in the future ๐Ÿ˜œ).

You can run build using configuration specifying it in args, like:

node build.js configuration1

Also to run build using configuration in release use:

node build.js configuration1 --release

You can read more about release in TypeScript section.

TypeScript

There are two compiling modes: Release and Debug.

  • Debug mode is used by default. To build in Release mode add --release or -r flag when running script.
  • Release mode compiles using tsconfig.release.json (you can use it to overwrite some settings in default tsconfig.json, like disable mappings).

e.g. to run build in Release mode, use node build.js --release (or -r).

ESBuild

Add esbuild to your configuration:

{
  esbuild: {
    entry: "src/index.ts", // Path to your entry point file
    outFile: "index.js" // Path to out file relative to CONFIG.destination
  }
}

You can also build with esbuild without bundling by omitting outFile:

{
  esbuild: {
    entry: "src/index.ts", // Path to your entry point file
  }
}

NPM

NPM is being run with npm install if there is package.json in the root folder.

See fancy stuff to disable this.

Fancy stuff

  • typescript: false - force-disable typescript.
  • npm: false - force-disable npm.

How to build (this build system ๐Ÿ˜)

  • Run tsc

You need TSC (TypeScript Compiler) to be installed in your environment.

build.js's People

Contributors

qt-kaneko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.