Skip to content

Commit

Permalink
Use standalone PostCSS task (no Gulp)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Feb 14, 2023
1 parent ee9aefc commit 4f23512
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 2 additions & 8 deletions postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ const unrgba = require('postcss-unrgba')
module.exports = (ctx) => {
const plugins = []

// PostCSS 'from' source path
// PostCSS 'from' (or webpack 'file') source path
// https://github.com/postcss/postcss-load-config#options
const file = ctx.from || ctx.file || ''

// Handle non-standard `file` source path
const { dir, name } = parse(typeof file === 'object'
? file.path // Vinyl file object (Gulp)
: file
)
const { dir, name } = parse(ctx.from || ctx.file || '')

// IE8 stylesheets
const isIE8 = name?.endsWith('-ie8') || name?.endsWith('-ie8.min')
Expand Down
18 changes: 17 additions & 1 deletion tasks/compile-stylesheets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { promisify } from 'util'

import { render } from 'node-sass'
import PluginError from 'plugin-error'
import postcss from 'postcss'
// eslint-disable-next-line import/default
import postcssrc from 'postcss-load-config'

import { paths, pkg } from '../config/index.js'
import { getListing } from '../lib/file-helper.js'
Expand Down Expand Up @@ -40,7 +43,7 @@ export async function compileStylesheet ([modulePath, { srcPath, destPath }]) {
const moduleDestPath = join(destPath, getPathByDestination(modulePath))

// Render Sass
const result = await sassRender({
const { css, map } = await sassRender({
file: moduleSrcPath,
outFile: moduleDestPath,

Expand All @@ -56,6 +59,19 @@ export async function compileStylesheet ([modulePath, { srcPath, destPath }]) {
]
})

const options = {
from: moduleSrcPath,
to: moduleDestPath,
map: {
inline: false,
prev: map.toString()
}
}

// Transform with PostCSS
const config = await postcssrc(options)
const result = await postcss(config.plugins).process(css, options)

// Write to files
return writeAsset(moduleDestPath, result)
}
Expand Down

0 comments on commit 4f23512

Please sign in to comment.