Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Provide the same API for config.optimization.minimizer as config.plugins #84

Merged
merged 3 commits into from
Oct 8, 2018

Conversation

guybarnard
Copy link
Contributor

@guybarnard guybarnard commented Aug 4, 2018

The config section has special plugin logic that allows .plugin(name).use(pluginclass) and merge functionality.

This pull request adds equivalent logic for optimization plugins (known as minimizers). This allows the configuration of such plugins to be changed as part of a neutrino environment (with arguments overriden before the plugin is actually initialized).

Fixes #95.

Copy link
Member

@eliperelman eliperelman left a comment

Choose a reason for hiding this comment

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

Just a change to the gitignore.

.gitignore Outdated Show resolved Hide resolved
@eliperelman
Copy link
Member

@edmorley this appears to be a breaking change, am I right?

@edmorley
Copy link
Member

Quite possibly? I guess we could add some more test cases to confirm?

@eliperelman
Copy link
Member

The API for minimizer is different:

// current:
minimizer(value) // returns Optimization instance

// proposed:
minimizer(name, value) // returns Plugin instance

So yeah, breaking change.

@eliperelman
Copy link
Member

@guycreate could you also update the README parts where this is changed? Thanks!

src/Optimization.js Outdated Show resolved Hide resolved
src/Optimization.js Show resolved Hide resolved
src/Optimization.js Outdated Show resolved Hide resolved
@guybarnard
Copy link
Contributor Author

Thanks for feedback. Implemented changes as best requested, by changing .gitignore to match coding standards, a call of .toConfig from config.js (and associated test), and readme to reflect the updated API. Agreed this is a breaking change.

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

@eliperelman this looks good to me with the final tweaks made - can you spot any other changes required? It would be good to get this merged/released soon, so I can start on neutrinojs/neutrino#1146. However given this change is breaking I was thinking we should perhaps get #107 merged/released as a semver patch before this PR is then released as a new major?

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@edmorley
Copy link
Member

edmorley commented Oct 2, 2018

@guycreate meant to say thank you for the changes - they look great, just a couple of small tweaks and this should be good to merge. If you'd prefer me to make those changes (given a few rounds of review already, so I don't want it to be too much of a pain!) just let me know :-)

@guybarnard
Copy link
Contributor Author

Thanks for continued feedback. I think this reflects the required changes, but feel free to edit directly if that's quicker/easier for additional edits.

Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

This looks great - thank you for the changes!

@eliperelman I'll likely merge/publish this as 5.0.0 tomorrow unless I hear back? Any other changes you'd like to see here, or else other breaking changes you'd like to see in v5?

@edmorley edmorley changed the title add Plugin logic to Optimization minimizers Provide the same API for config.optimization.minimizer as config.plugins Oct 8, 2018
@edmorley edmorley merged commit 18fca1f into neutrinojs:master Oct 8, 2018
@edmorley
Copy link
Member

edmorley commented Oct 8, 2018

Published as v5.0.0.

Thank you again for the PR! :-)

.tap(args => newArgs)

// Example
config
Copy link

Choose a reason for hiding this comment

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

Hi !
I think there is a small mistake here, as it should be config.optimization too :)

Copy link
Member

Choose a reason for hiding this comment

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

@Gramatiik, ah you're right. Would you be up for opening a PR? :-)

Copy link
Member

Choose a reason for hiding this comment

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

I've opened #159 :-)

edmorley added a commit that referenced this pull request Jan 3, 2020
Since as of #84 (which was released in webpack-chain 5.0.0), the
`optimization.minimizer` entries in the data structure passed to
`.merge()` must match that of the other plugin-like configuration.

Refs #204.
edmorley added a commit that referenced this pull request Jan 3, 2020
Since as of #84 (which was released in webpack-chain 5.0.0), the
`optimization.minimizer` entries in the data structure passed to
`.merge()` must match that of the other plugin-like configuration.

Refs #204.
edmorley added a commit that referenced this pull request Jan 3, 2020
In #84 (released as part of webpack-chain 5.0.0) the syntax for using
`optimization.minimizer` was altered, so that it matched that for
`plugin`, `resolve.plugin` and `resolveLoader.plugin`.

Syntax in webpack-chain 4:

```
config.optimization.minimizer([
  new WebpackPluginFoo(),
  new WebpackPluginBar(arg1, arg2),
]);
```

Syntax in webpack-chain 5+:

```
config.optimization.minimizer('foo').use(WebpackPluginFoo);
config.optimization.minimizer('bar').use(WebpackPluginBar, [arg1, arg2]);
```

Currently if someone uses the old syntax with newer webpack-chain, then
the `minimizer()` call succeeds, but later when `.toConfig()` is called,
the following error is generated:

`TypeError: Cannot read property '__expression' of undefined`

This PR adds an explicit check to `optimization.minimizer()` which
ensures a clearer error message is shown at point of use, so that the
stack trace is more relevant, and root cause clearer.

Refs:
#204 (comment)
edmorley added a commit that referenced this pull request Jan 7, 2020
In #84 (released as part of webpack-chain 5.0.0) the syntax for using
`optimization.minimizer` was altered, so that it matched that for
`plugin`, `resolve.plugin` and `resolveLoader.plugin`.

Syntax in webpack-chain 4:

```
config.optimization.minimizer([
  new WebpackPluginFoo(),
  new WebpackPluginBar(arg1, arg2),
]);
```

Syntax in webpack-chain 5+:

```
config.optimization.minimizer('foo').use(WebpackPluginFoo);
config.optimization.minimizer('bar').use(WebpackPluginBar, [arg1, arg2]);
```

Currently if someone uses the old syntax with newer webpack-chain, then
the `minimizer()` call succeeds, but later when `.toConfig()` is called,
the following error is generated:

`TypeError: Cannot read property '__expression' of undefined`

This PR adds an explicit check to `optimization.minimizer()` which
ensures a clearer error message is shown at point of use, so that the
stack trace is more relevant, and root cause clearer.

Refs:
#204 (comment)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

4 participants