Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cyntler/parcel-plugin-shebang

Plugin to generate shebang / hashbang for Parcel v1.x.x.
https://github.com/cyntler/parcel-plugin-shebang

hashbang parcel-bundler parcel-plugin shebang

Last synced: 9 days ago
JSON representation

Plugin to generate shebang / hashbang for Parcel v1.x.x.

Awesome Lists containing this project

README

        

[![npm-version](https://img.shields.io/npm/v/parcel-plugin-shebang.svg)](https://www.npmjs.com/package/parcel-plugin-shebang)
[![npm-download](https://img.shields.io/npm/dt/parcel-plugin-shebang.svg)](https://www.npmjs.com/package/parcel-plugin-shebang)

# parcel-plugin-shebang
> \#!/usr/bin/env node

Do you want your bundles generated by Parcel to have a **shebang** and it was easy to start from the console? This plugin allows this. You can build CLI applications in a simple way!

## Installing

To install the plugin simply download the module.

You can use npm for this.

```shell
npm i -D parcel-plugin-shebang
```

## Getting Started

After successful installation, the plugin should work.

If you use this plugin without [configuration](#configuration) (which is described below) it will generate for you shebang automagically. However, the plugin only **works when** it finds a shebang line in source files that are `entry points` of Parcel.

> Without this plugin, if you place a shebang line in the source file, Parcel will leave it in code and treat it the same as normal JavaScript code. Unfortunately, after running this file you will get `SyntaxError`. This plugin is designed to move the shebang line to the very top of the file so that it does not cause any syntax problems.

Here you can find a problem that tries to solve this plugin:

https://github.com/parcel-bundler/parcel/issues/2381

## Configuration

The plugin has an **optional configuration** that allows you to generate shebang in bundle files. This is useful if you want your source files to not have a shebang.

There are two ways to configure the plugin:
- You can use a dedicated configuration `.shebangrc` file.
- Alternatively, you can save the configuration in the `package.json` file.

The configuration of the plugin is an array of objects describing the name of the interpreter and the array of files for which this interpreter is to be used.

> An array can contain many objects.
If the path to the file repeats in the next object, the interpreter from the first passed object containing the given file will be used.

| Name | Type | Description |
| ------------- |----------| ---------------------------------------------------------------------------- |
| `interpreter` | string | Name of interpreter. |
| `files` | string[] | Array of relative paths to the files in which the interpreter is to be used. |


.shebangrc
```json
[
{
"interpreter": "node",
"files": [
"./cli.ts"
]
}
]
```

package.json
```json
"shebang": [
{
"interpreter": "node",
"files": [
"./cli.ts"
]
}
]
```

**Now if you run the command:**

```shell
parcel build ./cli.ts
```

The resulting file should contain a shebang with a `node` interpreter.