Naughty Program Manipulator
Learn how companies like Phone2Action are using npm in their front-end developmentJoin the conversation »

parcel-plugin-shebang

1.2.8 • Public • Published

npm-version npm-download

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 Yarn or npm for this.

yarn add -D parcel-plugin-shebang  # Yarn 
npm i -D parcel-plugin-shebang     # npm 

Getting Started

After successful installation, the plugin should work.
If you use this plugin without 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

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

package.json

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

Now if you run the command:

parcel build ./cli.ts

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

Install

npm i parcel-plugin-shebang

DownloadsWeekly Downloads

58

Version

1.2.8

License

MIT

Unpacked Size

15.2 kB

Total Files

12

Last publish

Collaborators

  • avatar