Skip to content

Commit

Permalink
Always run PostCSS cssnano() plugin after other transforms
Browse files Browse the repository at this point in the history
We now minify CSS by default but need to move `cssnano` after other transforms

This fixes a bug where minified CSS (with complex consolidated selectors) wasn’t correctly transformed by `postcss-pseudo-classes` to include all psuedo classes
  • Loading branch information
colinrotherham committed Jan 19, 2023
1 parent e37f173 commit d5903b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 55 deletions.
8 changes: 3 additions & 5 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ module.exports = ({ env, file = '' }) => {
autoprefixer({ env: isIE8 ? 'oldie' : env })
]

// Minify CSS
if (name.endsWith('.min')) {
plugins.push(cssnano())
}

// Add review app auto-generated 'companion' classes for each pseudo-class
// For example ':hover' and ':focus' classes to simulate form label states
if (minimatch(dir, '**/app/assets/scss')) {
Expand All @@ -58,6 +53,9 @@ module.exports = ({ env, file = '' }) => {
)
}

// Always minify CSS
plugins.push(cssnano())

return {
plugins
}
Expand Down
59 changes: 9 additions & 50 deletions postcss.config.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,49 +79,6 @@ describe('PostCSS config', () => {
)('Adds plugins for $path', ({ path }) => {
const input = new Vinyl({ path })

// Confirm plugins for both file object and path
for (const file of [input, input.path]) {
const config = configFn({ env, file })

expect(getPluginNames(config))
.toEqual(['autoprefixer'])
}
})
})

describe('Default + IE8', () => {
it.each(
[
{ path: 'example-ie8.css' },
{ path: 'example-ie8.scss' }
]
)('Adds plugins for $path', ({ path }) => {
const input = new Vinyl({ path })

// Confirm plugins for both file object and path
for (const file of [input, input.path]) {
const config = configFn({ env, file })

expect(getPluginNames(config))
.toEqual([
'autoprefixer',
'postcss-unmq',
'postcss-unopacity',
'postcss-color-rgba-fallback'
])
}
})
})

describe('Default + Minification', () => {
it.each(
[
{ path: 'example.min.css' },
{ path: 'example.min.scss' }
]
)('Adds plugins for $path', ({ path }) => {
const input = new Vinyl({ path })

// Confirm plugins for both file object and path
for (const file of [input, input.path]) {
const config = configFn({ env, file })
Expand All @@ -135,11 +92,11 @@ describe('PostCSS config', () => {
})
})

describe('Default + Minification + IE8', () => {
describe('Default + IE8', () => {
it.each(
[
{ path: 'example-ie8.min.css' },
{ path: 'example-ie8.min.scss' }
{ path: 'example-ie8.css' },
{ path: 'example-ie8.scss' }
]
)('Adds plugins for $path', ({ path }) => {
const input = new Vinyl({ path })
Expand All @@ -151,10 +108,10 @@ describe('PostCSS config', () => {
expect(getPluginNames(config))
.toEqual([
'autoprefixer',
'cssnano',
'postcss-unmq',
'postcss-unopacity',
'postcss-color-rgba-fallback'
'postcss-color-rgba-fallback',
'cssnano'
])
}
})
Expand All @@ -176,7 +133,8 @@ describe('PostCSS config', () => {
expect(getPluginNames(config))
.toEqual([
'autoprefixer',
'postcss-pseudo-classes'
'postcss-pseudo-classes',
'cssnano'
])
}
})
Expand Down Expand Up @@ -218,7 +176,8 @@ describe('PostCSS config', () => {
'postcss-pseudo-classes',
'postcss-unmq',
'postcss-unopacity',
'postcss-color-rgba-fallback'
'postcss-color-rgba-fallback',
'cssnano'
])
}
})
Expand Down

0 comments on commit d5903b3

Please sign in to comment.