-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I needed an indirect way to reference 'require' without tripping up Webpack. My previous code didn't work properly.
- Loading branch information
John Vilk
committed
Aug 18, 2016
1 parent
231bbfc
commit c324416
Showing
4 changed files
with
27 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* The only way I could figure out how to get a handle on Node's 'require' | ||
* function without confusing webpack. Using a Function constructor doesn't work, | ||
* as require() isn't in its scope! | ||
* | ||
* Isolating in its own module so it doesn't mess up mangling in other modules. | ||
*/ | ||
export default function getGlobalRequire(): Function { | ||
const reqVar = eval('typeof(require)!=="undefined"?require:null'); | ||
return reqVar ? reqVar : function(moduleName: string): any { | ||
throw new Error(`Cannot find module ${moduleName}`); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters