Skip to content

Commit

Permalink
refactor!: 💥 ♻️ renamed the config file from esbuild.config.js -> esb…
Browse files Browse the repository at this point in the history
…uild-runner.config.js
  • Loading branch information
folke committed May 29, 2021
1 parent 3cb62ff commit 728518d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The easiest way to use **esbuild-runner** is to install it globally and use the
$ esr hello-world.ts
```

Alternatively, you can *require* **esbuild-runner** within any nodejs process to include realtime transpilation:
Alternatively, you can _require_ **esbuild-runner** within any nodejs process to include realtime transpilation:

```shell
$ node -r esbuild-runner/register hello-world.ts
Expand All @@ -28,7 +28,8 @@ module.exports = {
}
```

VSCode Debugging
VSCode Debugging

```JSON
{
"version": "0.2.0",
Expand All @@ -50,12 +51,13 @@ VSCode Debugging
]
}
```

## ⚙️ Configuration

`esr` provides two different ways to transpile your code:

* **bundling** *(default)*: this transpiles the script and all its dependencies in typically one invocation of **esbuild**. Dependencies defined in `package.json` or `node_modules` will never be transpiled. Running `esr` will **always** transpile the code. No caching is used.
* **transform** *(`--cache`)*: this method will invoke **esbuild** for **every source file**, but will cache the result. This means that the initial run will be slower, but after that, only changed source files will be transpiled.
- **bundling** _(default)_: this transpiles the script and all its dependencies in typically one invocation of **esbuild**. Dependencies defined in `package.json` or `node_modules` will never be transpiled. Running `esr` will **always** transpile the code. No caching is used.
- **transform** _(`--cache`)_: this method will invoke **esbuild** for **every source file**, but will cache the result. This means that the initial run will be slower, but after that, only changed source files will be transpiled.

```shell
$ bin/esr.js --help
Expand All @@ -64,34 +66,34 @@ Usage: esr [options] <source-file> [file-options]
--cache Transform on a file per file basis and cache code
--clearCache Clear transform cache
--help|-h Display this help message

```

To customize the options passed to esbuild, you can create an `esbuild.config.js` file in the current directory or one of the ancestor directories.
To customize the options passed to esbuild, you can create an `esbuild-runner.config.js` file in the current directory or one of the ancestor directories.

```js
// example esbuild.config.js
// example esbuild-runner.config.js
module.exports = {
type: "bundle", // bundle or transform (see description above)
esbuild: {
// Any esbuild build or transform options go here
target: "esnext"
}
target: "esnext",
},
}
```

## 📦 Installation

Simply install the **esbuild-runner** npm package using your favorite package manager.

* globally ...
- globally ...

```shell
$ npm install -g esbuild-runner
```

* ... or locally in your project
- ... or locally in your project

```shell
$ npm add --dev esbuild-runner
```
Expand Down
6 changes: 4 additions & 2 deletions src/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ export function findUp(name: string, cwd = process.cwd()): string | undefined {
}

function loadConfig() {
const configFile = findUp("esbuild.config.js")
const configFile = findUp("esbuild-runner.config.js")
if (configFile) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
const ret = require(configFile) as TranspileOptions
return ret
} catch (error) {
// eslint-disable-next-line no-console
console.error(`[esbuild-runner] could not load "esbuild.config.js"\n`)
console.error(
`[esbuild-runner] could not load "esbuild-runner.config.js"\n`
)
throw error
}
}
Expand Down

0 comments on commit 728518d

Please sign in to comment.