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

Commit

Permalink
Feature: upgrade webpack-chain to use .before() and .after() (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliperelman authored Oct 6, 2017
1 parent a4e7f64 commit 3aa2666
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 26 deletions.
135 changes: 115 additions & 20 deletions docs/webpack-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,30 @@ values()
// where the key is the object property, and the value
// corresponding to the key. Will return `undefined` if the backing
// Map is empty.
// This will order properties by their name if the value is
// a ChainedMap that used .before() or .after().
// returns: Object, undefined if empty
entries()
````

```js
// Provide an object which maps its properties and values
// into the backing Map as keys and values.
// You can also provide an array as the second argument
// for property names to omit from being merged.
// obj: Object
merge(obj)
// omit: Optional Array
merge(obj, omit)
```

```js
// Conditionally execute a function to continue configuration
// condition: Boolean
// truthyHandler: Function -> ChainedMap
// whenTruthy: Function -> ChainedMap
// invoked when condition is truthy, given a single argument of the ChainedMap instance
// falsyHandler: Function -> ChainedMap
// whenFalsy: Optional Function -> ChainedMap
// invoked when condition is falsy, given a single argument of the ChainedMap instance
when(condition, truthyHandler, falsyHandler)
when(condition, whenTruthy, whenFalsy)
```

## ChainedSet
Expand Down Expand Up @@ -231,11 +236,11 @@ merge(arr)
```js
// Conditionally execute a function to continue configuration
// condition: Boolean
// truthyHandler: Function -> ChainedSet
// whenTruthy: Function -> ChainedSet
// invoked when condition is truthy, given a single argument of the ChainedSet instance
// falsyHandler: Function -> ChainedSet
// whenFalsy: Optional Function -> ChainedSet
// invoked when condition is falsy, given a single argument of the ChainedSet instance
when(condition, truthyHandler, falsyHandler)
when(condition, whenTruthy, whenFalsy)
```

## Shorthand methods
Expand Down Expand Up @@ -307,7 +312,7 @@ neutrino.config
neutrino.config
.entry(name)
.clear()
.clear()
// Using low-level config.entryPoints:
Expand Down Expand Up @@ -523,37 +528,37 @@ _NOTE: Do not use `new` to create the plugin, as this will be done for you._
```js
neutrino.config
.plugin(name)
.use(WebpackPlugin, args)
.use(WebpackPlugin, args)
// Examples
neutrino.config
.plugin('hot')
.use(webpack.HotModuleReplacementPlugin);
.use(webpack.HotModuleReplacementPlugin);
neutrino.config
.plugin('env')
.use(webpack.EnvironmentPlugin, ['NODE_ENV']);
.use(webpack.EnvironmentPlugin, ['NODE_ENV']);
```

#### Config plugins: modify arguments

```js
neutrino.config
.plugin(name)
.tap(args => newArgs)
.tap(args => newArgs)
// Example
neutrino.config
.plugin('env')
.tap(args => [...args, 'SECRET_KEY']);
.tap(args => [...args, 'SECRET_KEY']);
```

#### Config plugins: modify instantiation

```js
neutrino.config
.plugin(name)
.init((Plugin, args) => new Plugin(...args));
.init((Plugin, args) => new Plugin(...args));
```

#### Config plugins: removing
Expand All @@ -562,6 +567,48 @@ neutrino.config
neutrino.config.plugins.delete(name)
```

#### Config plugins: ordering before

Specify that the current `plugin` context should operate before another named `plugin`.
You cannot use both `.before()` and `.after()` on the same plugin.

```js
neutrino.config
.plugin(name)
.before(otherName)
// Example
neutrino.config
.plugin('html-template')
.use(HtmlWebpackTemplate)
.end()
.plugin('script-ext')
.use(ScriptExtWebpackPlugin)
.before('html-template');
```

#### Config plugins: ordering after

Specify that the current `plugin` context should operate after another named `plugin`.
You cannot use both `.before()` and `.after()` on the same plugin.

```js
neutrino.config
.plugin(name)
.after(otherName)
// Example
neutrino.config
.plugin('html-template')
.after('script-ext')
.use(HtmlWebpackTemplate)
.end()
.plugin('script-ext')
.use(ScriptExtWebpackPlugin);
```

#### Config resolve plugins

```js
Expand All @@ -576,23 +623,23 @@ _NOTE: Do not use `new` to create the plugin, as this will be done for you._
```js
neutrino.config.resolve
.plugin(name)
.use(WebpackPlugin, args)
.use(WebpackPlugin, args)
```

#### Config resolve plugins: modify arguments

```js
neutrino.config.resolve
.plugin(name)
.tap(args => newArgs)
.tap(args => newArgs)
```

#### Config resolve plugins: modify instantiation

```js
neutrino.config.resolve
.plugin(name)
.init((Plugin, args) => new Plugin(...args))
.init((Plugin, args) => new Plugin(...args))
```

#### Config resolve plugins: removing
Expand All @@ -601,6 +648,48 @@ neutrino.config.resolve
neutrino.config.resolve.plugins.delete(name)
```

#### Config resolve plugins: ordering before

Specify that the current `plugin` context should operate before another named `plugin`.
You cannot use both `.before()` and `.after()` on the same resolve plugin.

```js
neutrino.config.resolve
.plugin(name)
.before(otherName)
// Example
neutrino.config.resolve
.plugin('beta')
.use(BetaWebpackPlugin)
.end()
.plugin('alpha')
.use(AlphaWebpackPlugin)
.before('beta');
```

#### Config resolve plugins: ordering after

Specify that the current `plugin` context should operate after another named `plugin`.
You cannot use both `.before()` and `.after()` on the same resolve plugin.

```js
neutrino.config.resolve
.plugin(name)
.after(otherName)
// Example
neutrino.config.resolve
.plugin('beta')
.after('alpha')
.use(BetaWebpackTemplate)
.end()
.plugin('alpha')
.use(AlphaWebpackPlugin);
```

#### Config node

```js
Expand Down Expand Up @@ -805,7 +894,9 @@ neutrino.config.merge({
plugin: {
[name]: {
plugin: WebpackPlugin,
args: [...args]
args: [...args],
before,
after
}
},
Expand Down Expand Up @@ -863,7 +954,9 @@ neutrino.config.merge({
plugin: {
[name]: {
plugin: WebpackPlugin,
args: [...args]
args: [...args],
before,
after
}
}
},
Expand Down Expand Up @@ -901,7 +994,9 @@ neutrino.config.merge({
use: {
[name]: {
loader: LoaderString,
options: LoaderOptions
options: LoaderOptions,
before,
after
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neutrino/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"ora": "^1.2.0",
"ramda": "^0.24.1",
"webpack": "^3.6.0",
"webpack-chain": "^4.3.0",
"webpack-chain": "^4.4.1",
"webpack-dev-server": "^2.9.1",
"yargs": "^9.0.1"
}
Expand Down
12 changes: 7 additions & 5 deletions packages/neutrino/yarn.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# yarn v0.25.4
# node v8.6.0


abbrev@1:
Expand Down Expand Up @@ -626,7 +628,7 @@ deep-sort-object@^1.0.2:
dependencies:
is-plain-object "^2.0.1"

deepmerge@^1.5.1, deepmerge@^1.5.2:
deepmerge@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-1.5.2.tgz#10499d868844cdad4fee0842df8c7f6f0c95a753"

Expand Down Expand Up @@ -2888,11 +2890,11 @@ wbuf@^1.1.0, wbuf@^1.7.2:
dependencies:
minimalistic-assert "^1.0.0"

webpack-chain@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-4.3.0.tgz#8b88b371d2a728ea4ff3e37751db9800fad78948"
webpack-chain@^4.4.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/webpack-chain/-/webpack-chain-4.4.1.tgz#28b63729d02ea45e033c07962570933aa0b0dcb8"
dependencies:
deepmerge "^1.5.1"
deepmerge "^1.5.2"

webpack-dev-middleware@^1.11.0:
version "1.12.0"
Expand Down

0 comments on commit 3aa2666

Please sign in to comment.