Webpack: Require module every time some other module is required

Created on 28 Oct 2014  路  3Comments  路  Source: webpack/webpack

How can I tell webpack to automatically do:

require('es5-shim/es5-shim');
require('es5-shim/es5-sham');

Every time I require('react')?

I have multiple entry points in the same project, and I would want to avoid pasting the requires everywhere.

Also, my tests are running on PhantomJS 1.9, which doesn't implement Function.bind, so I'd also benefit from automatically requiring the shims there...

Most helpful comment

You can use the imports-loader to inject the requires:

module: { loaders: [
  { test: require.resolve("react"), loader: "imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham" }
]}

You can also try: https://github.com/deepsweet/autopolyfiller-loader

All 3 comments

You can use the imports-loader to inject the requires:

module: { loaders: [
  { test: require.resolve("react"), loader: "imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham" }
]}

You can also try: https://github.com/deepsweet/autopolyfiller-loader

Nice, thank you very much!

@sokra
Thank you for your answer!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tjorriemorrie picture Tjorriemorrie  路  3Comments

haohcraft picture haohcraft  路  3Comments

nicksparks picture nicksparks  路  3Comments

nwhite89 picture nwhite89  路  3Comments

d4goxn picture d4goxn  路  3Comments