Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: add ability to scope aliases #9690

Closed
OliverJAsh opened this issue Sep 12, 2019 · 2 comments
Closed

Suggestion: add ability to scope aliases #9690

OliverJAsh opened this issue Sep 12, 2019 · 2 comments

Comments

@OliverJAsh
Copy link

OliverJAsh commented Sep 12, 2019

Feature request

What is motivation or use case for adding/changing the behavior?
We are using aliases to make our client-side code use the ES Modules version of Lodash (lodash-es)—so that we get tree shaking—whilst the server-side code continues to use the old CommonJS version of Lodash (lodash). (Node does not yet support ES Modules.)

resolve: {
  alias: {
    lodash: 'lodash-es'
  }
}

The downside to doing this is that aliases are applied globally, which means they will be applied to all modules including those inside node_modules (which could even need their own version of Lodash altogether).

This behaviour actually caused a bug in our application: gaearon/react-hot-loader#1269

How should this be implemented in your opinion?
It should be possible to scope aliases, just like you can with ES Modules’ import maps, e.g. this could look like:

resolve: {
  alias: {
    lodash: 'lodash-es',
  },
  scopes: {
    'node_modules': {
      lodash: 'lodash'
    }
  }
}

Are you willing to work on this yourself?
yes

@sokra
Copy link
Member

sokra commented Sep 12, 2019

You can put resolve options in rules. Example:

module.rules: [
  {
    include: path.resolve(__dirname, "src"),
    resolve: {
      alias: { lodash: "lodash-es" }
    }
  }
]

@OliverJAsh
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants