Closed wrobel closed 9 years ago
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.
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 :)
Released on npm as 1.0.0
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"])".