Skip to content

Commit

Permalink
Use standalone PostCSS task for package
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Feb 14, 2023
1 parent 4f23512 commit ffa02d7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 246 deletions.
1 change: 1 addition & 0 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ gulp.task('build:package', gulp.series(
clean,
copyFiles,
compileJavaScripts,
compileStylesheets,
updatePrototypeKitConfig
))

Expand Down
209 changes: 0 additions & 209 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"glob": "^8.1.0",
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"gulp-postcss": "^9.0.1",
"gulp-rename": "^2.0.0",
"gulp-task-listing": "^1.1.1",
"js-yaml": "^4.1.0",
Expand Down
20 changes: 13 additions & 7 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const autoprefixer = require('autoprefixer')
const cssnano = require('cssnano')
const cssnanoPresetDefault = require('cssnano-preset-default')
const { minimatch } = require('minimatch')
const postcss = require('postcss')
const pseudoclasses = require('postcss-pseudo-classes')
const scss = require('postcss-scss')
const unmq = require('postcss-unmq')
const unopacity = require('postcss-unopacity')
const unrgba = require('postcss-unrgba')
Expand All @@ -17,6 +19,7 @@ const unrgba = require('postcss-unrgba')
*/
module.exports = (ctx) => {
const plugins = []
const syntax = ctx.to?.endsWith('.scss') ? scss : postcss

// PostCSS 'from' (or webpack 'file') source path
// https://github.com/postcss/postcss-load-config#options
Expand Down Expand Up @@ -55,15 +58,18 @@ module.exports = (ctx) => {
}

// Always minify CSS
plugins.push(cssnano({
preset: [cssnanoPresetDefault, {
// Sorted CSS is smaller when gzipped, but we sort using Stylelint
// https://cssnano.co/docs/optimisations/cssdeclarationsorter/
cssDeclarationSorter: false
}]
}))
if (syntax !== scss) {
plugins.push(cssnano({
preset: [cssnanoPresetDefault, {
// Sorted CSS is smaller when gzipped, but we sort using Stylelint
// https://cssnano.co/docs/optimisations/cssdeclarationsorter/
cssDeclarationSorter: false
}]
}))
}

return {
syntax,
plugins
}
}
16 changes: 16 additions & 0 deletions postcss.config.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ describe('PostCSS config', () => {
})
})

describe('Sass syntax parser', () => {
it.each([
{
from: 'src/govuk/components/accordion/_accordion.scss',
to: 'package/govuk/components/accordion/_accordion.scss'
}
])('Adds plugins for $from', ({ from, to }) => {
const config = configFn({ env, from, to })

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

describe('Review app only', () => {
it.each([
{
Expand Down
Loading

0 comments on commit ffa02d7

Please sign in to comment.