Skip to content

Add Encore.addAliases and Encore.addExternals methods #217

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

Merged
merged 1 commit into from
Feb 11, 2018

Conversation

Lyrkan
Copy link
Collaborator

@Lyrkan Lyrkan commented Nov 25, 2017

This PR adds two new methods to the API (closes #200):

  • Encore.addAliases: Adds the given values to the resolve.alias setting of the generated config
  • Encore.addExternals: Adds the given values to the external setting of the generated config

@Lyrkan Lyrkan added the Feature New Feature label Dec 4, 2017
@lambertbeekhuis
Copy link

Can you merge this!!

@weaverryan
Copy link
Member

Thanks @Lyrkan! Sorry for the wait :)

@weaverryan weaverryan merged commit eefe8a4 into symfony:master Feb 11, 2018
weaverryan added a commit that referenced this pull request Feb 11, 2018
…yrkan)

This PR was merged into the master branch.

Discussion
----------

Add Encore.addAliases and Encore.addExternals methods

This PR adds two new methods to the API (closes #200):

* **`Encore.addAliases`**: Adds the given values to the `resolve.alias` setting of the generated config
* **`Encore.addExternals`**: Adds the given values to the `external` setting of the generated config

Commits
-------

eefe8a4 Add Encore.addAliases and Encore.addExternals methods
@@ -77,7 +77,7 @@ class ConfigGenerator {

config.resolve = {
extensions: ['.js', '.jsx', '.vue', '.ts', '.tsx'],
alias: {}
alias: this.webpackConfig.aliases
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should create a copy of it, so that modifying the generated webpack config object cannot modify the Encore config (which might be used again, even if it is probably only an edge case to reuse it without resetting).
this also applies to externals.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, nice catch, I'll open a new PR for that.

I'm a bit worried that there is the same issue with other objects though... for instance when calling Encore.addLoader() and Encore.addPlugin().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we don't mutate the object ourselves, it might be less of an issue. but here, we are doing the mutation ourselves in some cases

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

Successfully merging this pull request may close these issues.

How to add alias and externals in encore
4 participants