Trying to figure out how to use this. Do I need to require('webpack') in my commonjs module?
I basically want Webpack to ignore a module that I'm requiring.
__non_webpack_require__ is the original require function which exists in the environment before webpack comes in.
Ignoring modules is a separate thing.
You can do that with the browser field, the IgnorePlugin or resolve.alias.
I cannot believe how long it has taken me to find __non_webpack_require__. All I wanted to do was require at runtime and I ended up finding require.ensure, System.import, await import(). All of which didn't work for a fully dynamic require.
Is it possible to get more documentation for this keyword? Also why isn't there a require.dynamic() or require.runtime() function, is there a reason webpack doesn't do this?
P.S. My use case was to read a config.js file which has its filename provided at runtime via a command line flag.
__non_webpack_require__is the originalrequirefunction which exists in the environment before webpack comes in.Ignoring modules is a separate thing.
You can do that with the
browserfield, the IgnorePlugin or resolve.alias.
_Just_ incase the above isn't clear enough for anyone who stumbles upon this in the future,
you literally just have to replace:
const someModule = require('some-module)
...with:
const someModule = __non_webpack_require__('some-module)
Most helpful comment
I cannot believe how long it has taken me to find
__non_webpack_require__. All I wanted to do was require at runtime and I ended up findingrequire.ensure,System.import,await import(). All of which didn't work for a fully dynamic require.Is it possible to get more documentation for this keyword? Also why isn't there a
require.dynamic()orrequire.runtime()function, is there a reason webpack doesn't do this?P.S. My use case was to read a config.js file which has its filename provided at runtime via a command line flag.