Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore a global "module" variable #6

Closed
wants to merge 1 commit into from
Closed

Ignore a global "module" variable #6

wants to merge 1 commit into from

Conversation

wrobel
Copy link

@wrobel wrobel commented Oct 29, 2014

In case global scope has a variable "module" rewire-webpack will include
this variable into the rewired module using "var module = ...". The
function in getImportGlobalsSrc.js is responsible for copying the
globals into such "var ... = ..." definitions.

Webpack however starts each module with the following function wrapper:
"function(module, exports, webpack_require) {...}"

Having a "var module = ..." statement within this function will shadow
the "module" parameter from the function definition.

In consequence the module cannot export anything anymore as it exports
to a local variable.

This can be fixed by instructing getImportGlobalsSrc() to ignore the
module variable via "getImportGlobalsSrc(["module"])".

In case global scope has a variable "module" rewire-webpack will include
this variable into the rewired module using "var module = ...". The
function in getImportGlobalsSrc.js is responsible for copying the
globals into such "var ... = ..." definitions.

Webpack however starts each module with the following function wrapper:
"function(module, exports, __webpack_require__) {...}"

Having a "var module = ..." statement within this function will shadow
the module variable.

In consequence the module cannot export anything anymore as it exports
to a local variable.

This can be fixed by instructing getImportGlobalsSrc() to ignore the
module variable via "getImportGlobalsSrc(["module"])".
@jhnns
Copy link
Owner

jhnns commented Oct 30, 2014

Mhmmm ... you're right. But this is only the case when there is a window.module-variable. Otherwise getImportGlobalsSrc() won't generate code that shadows the module-variable.

I'm thinking of ignoring module and exports in rewire itself because overriding these values doesn't make sense at all.

@wrobel
Copy link
Author

wrobel commented Oct 31, 2014

We do have the window.module variable as we pull in angular-mocks for our Karma based tests. I was suprised to see that this seems to be something people did not encounter before when using rewire-webpack in an angular based setup.

Ignoring them within rewire would be fine for us as well :)

jhnns added a commit to jhnns/rewire that referenced this pull request Nov 4, 2014
@jhnns
Copy link
Owner

jhnns commented Nov 4, 2014

Released on npm as 1.0.0

@jhnns jhnns closed this Nov 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants