Skip to content

Commit

Permalink
Support the Array version of deprecated webpack.postcss config
Browse files Browse the repository at this point in the history
  • Loading branch information
insin committed Jan 25, 2017
1 parent e1e2017 commit 1efe259
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
25 changes: 13 additions & 12 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**Changed:**

- Support the Array version of deprecated `webpack.postcss` config.
- Tell the user they're including redundant config if they've manually configured inferno-compat or preact-compat aliases for React modules [[#247](https://github.com/insin/nwb/issues/247)]

# 0.15.3 / 2017-01-25
Expand Down Expand Up @@ -106,22 +107,22 @@
}
```

- Configuring PostCSS plugins with `webpack.postcss` is no longer supported - use [`webpack.rules` config](https://github.com/insin/nwb/blob/master/docs/Configuration.md#configuring-postcss) instead:
- Deprecated configuring PostCSS plugins with special `webpack.postcss` config - postcss-loader can now be configured like any other loader using [`webpack.rules` config](https://github.com/insin/nwb/blob/master/docs/Configuration.md#configuring-postcss):

```js
// < v0.15 // v0.15
module.exports = { module.exports = {
webpack: { webpack: {
postcss: { => rules: {
defaults: [ postcss: {
require('precss')(), plugins: [
require('autoprefixer')() require('precss')(),
], require('autoprefixer')()
} ]
} }
} }
// < v0.15 // v0.15
module.exports = { module.exports = {
webpack: { webpack: {
postcss: [ => rules: {
require('precss')(), postcss: {
require('autoprefixer')() plugins: [
] require('precss')(),
} require('autoprefixer')()
} ]
}
}
}
}
```

**Removed:**
Expand Down
11 changes: 6 additions & 5 deletions src/getUserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,17 @@ export function processUserConfig({
}
// TODO Remove in a future version
if ('postcss' in userConfig.webpack) {
let messages = [`Deprecated as of nwb v0.15 - PostCSS plugins can now be configured in ${chalk.green('webpack.rules')} using postcss loader ids.`]
if (typeOf(userConfig.webpack.postcss) === 'object' &&
typeOf(userConfig.webpack.postcss.defaults) === 'array') {
let messages = [`Deprecated as of nwb v0.15 - PostCSS plugins are now configured in ${chalk.green('webpack.rules')} using postcss loader ids.`]
let configType = typeOf(userConfig.webpack.postcss)
if (configType === 'array' ||
(configType === 'object' && typeOf(userConfig.webpack.postcss.defaults) === 'array')) {
if (!('rules' in userConfig.webpack)) {
userConfig.webpack.rules = {}
}
userConfig.webpack.rules.postcss = {
plugins: userConfig.webpack.postcss.defaults
plugins: configType === 'array' ? userConfig.webpack.postcss : userConfig.webpack.postcss.defaults
}
messages.push(`nwb will use ${chalk.yellow('webpack.postcss.defaults')} as ${chalk.green('webpack.rules.postcss.plugins')} config during a build.`)
messages.push(`nwb will use ${chalk.yellow(`webpack.postcss${configType === 'object' ? '.defaults' : ''}`)} as ${chalk.green('webpack.rules.postcss.plugins')} config during a build.`)
}
else {
messages.push(`nwb will use its default PostCSS config during a build.`)
Expand Down
10 changes: 10 additions & 0 deletions tests/getUserConfig-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ describe('processUserConfig()', () => {
})
expect(config.webpack.rules).toEqual({css: {options: {a: 1}}})
})
it('converts PostCSS array config to loader option config for v0.15 back-compat', () => {
let config = processUserConfig({
userConfig: {
webpack: {
postcss: [43]
}
}
})
expect(config.webpack.rules).toEqual({postcss: {options: {plugins: [43]}}})
})
it('converts PostCSS defaults config to loader option config for v0.15 back-compat', () => {
let config = processUserConfig({
userConfig: {
Expand Down

0 comments on commit 1efe259

Please sign in to comment.