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

IngwiePhoenix picture IngwiePhoenix  路  3Comments

sairion picture sairion  路  3Comments

shairez picture shairez  路  3Comments

yannispanousis picture yannispanousis  路  3Comments

nwhite89 picture nwhite89  路  3Comments