microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
src/common/customRequire.ts
17lines · modeblame
2d8af448Yuri Skorokhodov6 years ago | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. | |
| 3 | | |
| 4 | // Portion of code was taken from https://github.com/sindresorhus/ow/blob/d62a06c192b892d504887f0b97fdc842e8cbf862/source/utils/node/require.ts | |
| 5 | let customRequire: (packageName: string) => any; | |
| 6 | | |
| 7 | try { | |
| 8 | // Export `__non_webpack_require__` in Webpack environments to make sure it doesn't bundle modules loaded via this method | |
| 9 | customRequire = (global as any).__non_webpack_require__ === "function" | |
| 10 | ? (global as any).__non_webpack_require__ | |
| 11 | : eval("require"); // tslint:disable-line:no-eval | |
| 12 | } catch { | |
| 13 | // Use a noop in case both `__non_webpack_require__` and `require` does not exist | |
| 14 | customRequire = () => {}; // tslint:disable-line:no-empty | |
| 15 | } | |
| 16 | | |
| 17 | export default customRequire; |