When entry file has a shebang, output it in the first line of the bundle
See original GitHub issue🙋 feature request
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.
🤔 Expected Behavior
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
😯 Current Behavior
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
)
🔦 Context
I run into this when trying to make executable scripts for node which have all their files already bundled.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Why should the shebang line always be the first line?
The shebang must be the first line because it is interpreted by the kernel, which looks at the two bytes at the start...
Read more >How to Use the Shebang in Bash and Python - Linode
A Shebang directive, which always begins with the sequence #! , can sometimes be found on the first line of a Bash or...
Read more >Shebang (Unix) - Wikipedia
In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark ( #!) at the beginning of...
Read more >What is the language that appears on the first line of a script?
It's called a shebang. en.wikipedia.org/wiki/Shebang_(Unix). When Unix loads this file into memory, the #! tells the exec function to make use ...
Read more >webpack-shebang-plugin - npm
#!/usr/bin/env node // The first line is the shebang you want be added. ... two different entries, and you wish to have two...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You need to make sure Parcel knows that you’re build for a Node target, not for the browser. The easiest way to achieve that is adding
to your package.json
@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
.