Skip to content

Commit bba29a8

Browse files
Merge pull request #1371 from nhsuk/build-sass
Add Gulp build output for Sass
2 parents 9870997 + 94bdb23 commit bba29a8

8 files changed

Lines changed: 203 additions & 195 deletions

File tree

package-lock.json

Lines changed: 22 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nhsuk-frontend/gulpfile.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { join } from 'path'
22

33
import * as config from '@nhsuk/frontend-config'
4-
import { scripts, styles } from '@nhsuk/frontend-tasks'
4+
import { scripts } from '@nhsuk/frontend-tasks'
55
import gulp from 'gulp'
66

7-
import { assets, release } from './tasks/index.mjs'
7+
import { assets, release, styles } from './tasks/index.mjs'
88

99
gulp.task('styles', styles.compile)
1010
gulp.task('scripts', scripts.compile)

packages/nhsuk-frontend/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@
4646
"@nhsuk/frontend-tasks": "*",
4747
"@testing-library/dom": "^10.4.0",
4848
"@testing-library/user-event": "^14.6.1",
49+
"autoprefixer": "^10.4.21",
50+
"cssnano": "^7.0.7",
4951
"del-cli": "^6.0.0",
52+
"glob": "^11.0.2",
5053
"gulp": "^5.0.1",
5154
"gulp-zip": "^6.1.0",
5255
"outdent": "^0.8.0",
56+
"postcss": "^8.5.4",
57+
"postcss-scss": "^4.0.9",
5358
"puppeteer": "^24.10.0",
5459
"sass-embedded": "^1.87.0"
5560
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import autoprefixer from 'autoprefixer'
2+
import cssnano from 'cssnano'
3+
import postcss from 'postcss'
4+
import scss from 'postcss-scss'
5+
6+
/**
7+
* PostCSS config
8+
*
9+
* @type {ConfigFn}
10+
*/
11+
export default (ctx = {}) => {
12+
const { to } = ctx
13+
14+
return {
15+
plugins: [
16+
// Add vendor prefixes
17+
autoprefixer({
18+
env: 'stylesheets'
19+
}),
20+
21+
// Minify CSS only
22+
to?.endsWith('.min.css') &&
23+
cssnano({
24+
env: 'stylesheets'
25+
})
26+
],
27+
28+
// Sass syntax support
29+
syntax: to?.endsWith('.scss') ? scss : postcss
30+
}
31+
}
32+
33+
/**
34+
* @import { ConfigFn } from 'postcss-load-config'
35+
*/

packages/nhsuk-frontend/tasks/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*/
44
export * as assets from './assets.mjs'
55
export * as release from './release.mjs'
6+
export * as styles from './styles.mjs'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { join } from 'path'
2+
3+
import * as config from '@nhsuk/frontend-config'
4+
import { styles, task } from '@nhsuk/frontend-tasks'
5+
import { glob } from 'glob'
6+
import gulp from 'gulp'
7+
8+
export const compile = gulp.series(
9+
/**
10+
* Transform NHS.UK frontend styles
11+
*/
12+
task.name('styles:transform', async () => {
13+
const modulePaths = await glob('nhsuk/**/*.scss', {
14+
cwd: join(config.paths.pkg, 'src'),
15+
nodir: true
16+
})
17+
18+
// Apply PostCSS transforms (e.g. vendor prefixes)
19+
for (const modulePath of modulePaths) {
20+
await styles.compile(modulePath, {
21+
srcPath: join(config.paths.pkg, 'src'),
22+
destPath: join(config.paths.pkg, 'dist'),
23+
output: { file: modulePath }
24+
})()
25+
}
26+
}),
27+
28+
/**
29+
* Compile NHS.UK frontend styles bundle
30+
*/
31+
task.name(
32+
'styles:compile',
33+
styles.compile('nhsuk/nhsuk.scss', {
34+
srcPath: join(config.paths.pkg, 'src'),
35+
destPath: join(config.paths.pkg, 'dist'),
36+
output: { file: 'nhsuk/nhsuk-frontend.min.css' }
37+
})
38+
)
39+
)

shared/tasks/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
"browser-sync": "^3.0.4",
1616
"cssnano": "^7.0.7",
1717
"gulp": "^5.0.1",
18-
"gulp-postcss": "^10.0.0",
1918
"gulp-rename": "^2.0.0",
20-
"gulp-sass": "^6.0.1",
2119
"plugin-error": "^2.0.1",
20+
"postcss": "^8.5.4",
21+
"postcss-load-config": "^5.1.0",
22+
"postcss-scss": "^4.0.9",
2223
"sass-embedded": "^1.87.0",
2324
"terser-webpack-plugin": "^5.3.14",
2425
"webpack-stream": "^7.0.0"

0 commit comments

Comments
 (0)