In UNIX systems, the first line of a script can be a shebang with the path to the interpreter. When the main entry file has this shebang (and optionally when target: node), this shebang line could be taken _out of the bundled modules_ and outputted in the first line of the bundle.
hello-world.js:
#!/usr/bin/env node
console.log("Hello, world!");
$ parcel build -t node hello-world.js
dist/hello-world.js:
#!/usr/bin/env node
// parcel bundle prologue ...function(require,module,exports) {
console.log("Hello, world!");
// }... parcel bundle epilogue
dist/hello-world.js:
// parcel bundle prologue ...function(require,module,exports) {
#!/usr/bin/env node
console.log("Hello, world!");
// }... parcel bundle epilogue
(which is actually a SyntaxError)
I run into this when trying to make executable scripts for node which have all their files already bundled.
@cprecioso, I created a plugin for this.
See: https://github.com/sintloer/parcel-plugin-shebang
@sintloer That's great, I'll start using it! Maybe you could copy the shebang of the entry file instead of having to define it in the package.json?
However, I still think parcel should have native support for this, especially as the input is a valid node script but the output is as SyntaxError.
@cprecioso, Yes, I think Parcel should support shebang natively.
As for my plugin - your idea is really good. I will want to implement it.
@cprecioso, new version of my plugin (1.2.0) supports copy the shebang of the entry file :)
@sintloer why didn't you contribute this directly to parcel core?
This seems like something that should be in core if detected?
@DeMoorJasper, it should be. It's a good idea.
I'll do it.
@sintloer any updates?
No progress still?
Most helpful comment
@sintloer That's great, I'll start using it! Maybe you could copy the shebang of the entry file instead of having to define it in the
package.json?However, I still think parcel should have native support for this, especially as the input is a valid node script but the output is as
SyntaxError.