Parcel: Do not include the parcelRequire helper if not necessary

Created on 22 Jan 2019  ยท  13Comments  ยท  Source: parcel-bundler/parcel

โ” Question


Is it possible to avoid the addition of the parcelRequire helper in the case of a JS bundle which does not use require or any sort of module feature in the target script?

๐Ÿ”ฆ Context


I pass a simple script to parcel which does not use any require or import and I'd like to reduce the overhead produced by parcel.

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel |1.11.0
| Node |8.11.3
| Yarn | 1.13.0
| Operating System |

Waiting Question

Most helpful comment

@devongovett Should this really be closed? An experimental flag is not the same as being completed.

All 13 comments

You could use --experimental-scope-hoisting.

(This is quite hard to implement in the current pipeline)

related to #2451

@mischnic As seen in #2451, the real problem that I have is the "Mismatched anonymous define()" error. Would it be that difficult to handle? What's your take on this @devongovett?

@mischnic How reliable is that flag? It certainly looks to work on trivial cases.

How reliable is that flag? It certainly looks to work on trivial cases.

It even works in most complex cases ๐Ÿ˜„. I'd say it's quite reliable now, there are only some edge cases left. Please try it and open an issue if you find one!

@mischnic As the flag is "experimental", any idea when this should be ready for production?

@devongovett Should this really be closed? An experimental flag is not the same as being completed.

The flag didn't work for me. For test purposes I only have one script file with a console.log() included at the end of my HTML file. So there is definitely no reason for parcelRequire() here.

This is my build task:

"build": "parcel build index.html --out-dir build --no-minify --no-source-maps --experimental-scope-hoisting",

If someone could explain to me, if I have a single js file - why do I need to require anything inside the js file (parcelRequire) if it's all inside that file? i.e. what is parcelRequire actually for?

why do I need

It isn't needed, but the current approach is: take the wrapper and insert all JS modules. The unfortunate side-effect of this simplification is that a single JS module also has the wrapper code.

@jhpratt I agree. Can we keep this open?

For Parcel 2, scope hoisting (which has no such wrapper) enabled by default in production builds. So I would say this is already somewhat fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jzimmek picture jzimmek  ยท  3Comments

medhatdawoud picture medhatdawoud  ยท  3Comments

dsky1990 picture dsky1990  ยท  3Comments

oliger picture oliger  ยท  3Comments

dotdash picture dotdash  ยท  3Comments