2.1.6 • Published 4 months ago

bun-build-userscript v2.1.6

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

Builds index.ts and header.txt (configurable) into a single js-file.

Replaces {version} in header.txt by version from package.json.

Install

bun add -D bun-build-userscript
# or
npm i -D bun-build-userscript

Usage

From package.json

{
  "scripts": {
    "build": "build-userscript",
    "watch": "build-userscript --watch"
  }
}

Globally

bun add --global bun-build-userscript

# build
build-userscript
# watch
build-userscript --watch

Globally (without installing)

# build
bunx bun-build-userscript
# watch
bunx bun-build-userscript --watch

Options

--version -v

Prints the current package version.

--watch

Listens for changes in the source file(s) and rebuilds.

--cfg

Path to your config.

build-userscript --cfg my_config.ts
# JavaScript is also supported
build-userscript --cfg my_config.js

Example config:

// EXPORTING BOTH `userscript` AND `bun` IS OPTIONAL.
// ALL OPTIONS ARE OPTIONAL

import type { BuildConfigs } from "bun-build-userscript";

export const userscript: BuildConfigs['userscript'] = {
  // may be useful in watch mode
  before: async ({ bun, userscript }) => {
    // you can add additional entrypoints
    bun.entrypoints.push(additionalFile);
    // or redefine some variables
    bun.define = JSON.parse(await readFile("constants.json", "utf8"));
  },
  transform: (code) => code;
  // default options (simplified)
  logErrors: process.argv.includes("--log-errors"),
  clearTerminal: !(isBuild || process.argv.includes("--no-clear")),
  header: getArg("--header") || "header.txt",
  entry: getArg("--entry") ||  "index.ts",
};

// BuildConfigs["bun"] is an alias to import("bun").BuildConfig
export const bun: BuildConfigs["bun"] = {
  // default options (simplified)
  // if you want to change entrypoints, it's better to use `userscript.before` instead
  entrypoints: [getIndexTs(userscript.entry)],
  naming: "script.user.js",
  outdir: ".",
};

--out

Output file path.

Default: user.script.js

Config: bun.naming (can be combined with bun.outdir)

build-userscript --out index.js

--log-errors

Do print errors to the browser console.

Default: false

Config: bun.logErrors

Recommended:

{
  logErrors: !process.argv.includes("--build"),
}

--no-clear

Disables clearing terminal in watch mode.

Default: false

Config: userscript.clearTerminal

--header

Path to your header file.

Default: header.txt or src/header.txt

Config: userscript.header

--entry

Path to your source file/dir.

If it's a directory, entry point is resolved to index.ts in this directory, but all files are watched in watch mode.

Default: index.ts or src/index.ts

Config: userscript.entry

--delay

Delay (milliseconds) between file change and build in watch mode.

Introduced because of the issue with bun not being able to find the changed file.

Default: 100

Config: not available

userscript.transform

NOT AVAILABLE IN CLI

Function to transform the code after it's built.

Async: not supported.

Default: undefined

userscript.before

NOT AVAILABLE IN CLI

Function to run before the build.

Takes modified bun and userscript objects, returns nothing.

Async: supported.

Default: undefined

2.1.6

4 months ago

2.1.5

4 months ago

1.6.3

5 months ago

2.1.2

5 months ago

2.0.3

5 months ago

2.1.1

5 months ago

2.0.2

5 months ago

2.1.4

5 months ago

2.1.3

5 months ago

2.0.4

5 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.6.2

6 months ago

1.6.1

6 months ago

1.6.0

7 months ago

1.5.0

8 months ago

1.4.6

9 months ago

1.4.5

9 months ago

1.4.4

10 months ago

1.4.3

10 months ago

1.4.2

11 months ago

1.4.1

12 months ago

1.4.0

1 year ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago