Webpack: Question: How does one use __non_webpack_require__?

Created on 29 Apr 2015  路  3Comments  路  Source: webpack/webpack

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.

question

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 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.

All 3 comments

__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 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.

 

_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)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zerkalica picture zerkalica  路  3Comments

Mithras picture Mithras  路  3Comments

natew picture natew  路  3Comments

unindented picture unindented  路  3Comments

nwhite89 picture nwhite89  路  3Comments