Prepack: Generate CommonJS Module Compatible Output

Created on 25 Apr 2017  路  2Comments  路  Source: facebook/prepack

Currently we generate output that ends with .call(this). This works fine in a global context. It would, however, be nice to be able to generate an output that doesn't assume that this is the global context so that it can run inside of a "module" and still be able to reach for the global object. In this context this is something else.

Perhaps we can detect if the global variable is available in the scope and conditionally use that? Otherwise fallback to this? I.e. .call(global || this)

cc @kittens

enhancement help wanted

Most helpful comment

I have a webpack bundle that has its target: "node". The bundle includes references to the real, not mocked, module, process, and require (to load fs or path). When I run prepack it errors out with:

module is not defined
ReferenceError

The output.libraryTarget is 'commonjs2' which means it's exporting to module.exports = ....

All 2 comments

Allowing module.exports and exports to be assigned to in this context would be good too. We just need to define some intrinsics for that.

I have a webpack bundle that has its target: "node". The bundle includes references to the real, not mocked, module, process, and require (to load fs or path). When I run prepack it errors out with:

module is not defined
ReferenceError

The output.libraryTarget is 'commonjs2' which means it's exporting to module.exports = ....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandipp picture sandipp  路  4Comments

matheusml picture matheusml  路  8Comments

phpnode picture phpnode  路  3Comments

simon-yxl picture simon-yxl  路  3Comments

kamranahmedse picture kamranahmedse  路  7Comments