Skip to content

Allow replacing options in configuration callbacks #298

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

Closed
stof opened this issue Apr 11, 2018 · 0 comments · Fixed by #300
Closed

Allow replacing options in configuration callbacks #298

stof opened this issue Apr 11, 2018 · 0 comments · Fixed by #300
Labels

Comments

@stof
Copy link
Member

stof commented Apr 11, 2018

Currently, the different configuration callbacks we expose are expecting to alter the options object directly.
But this makes it much harder to use libraries exposing a function processing options and returning new ones

#294 shows such a use case. #294 (comment) is showing the current code needed to handle it, while #294 (comment) shows how this could look like with this proposal.

The idea would be simple: inspect the return value of the callback when calling it:

  • if it is an object, use it as the new options object
  • if it is undefined (nothing was returned), keep using the existing options object (which may have been altered inside the callback, as done today).
@Lyrkan Lyrkan added the HasPR label Apr 12, 2018
weaverryan added a commit that referenced this issue Apr 14, 2018
…kan)

This PR was squashed before being merged into the master branch (closes #300).

Discussion
----------

Allow to replace options in configuration callbacks

This PR closes #298 by using the return value of callback functions (for loaders/plugins) as options if it is an object.

For instance:

```js
Encore.configureUglifyJsPlugin((options) => {
    return {
        ...options,
        beautify: true
    };
});
```

Commits
-------

3dfc787 Revert a forgotten 'let' to a 'const'
ef992c1 Replace duplicated 'options callback' logic by an utility method
ecb623c Allow to replace options in configuration callbacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants