Skip to content

Commit

Permalink
Ensure PostCSS outputs source maps for Sass sources
Browse files Browse the repository at this point in the history
We transform Sass sources (Autoprefixer only) but didn’t source map the changes
  • Loading branch information
colinrotherham committed Apr 20, 2023
1 parent ed3f083 commit b7acb29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions shared/tasks/build/package.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ describe('package/', () => {
return output
}))

// Add Autoprefixer prefixes to all source '*.scss' files
.flatMap(mapPathTo(['**/*.scss'], ({ dir: requirePath, name }) => [
join(requirePath, `${name}.scss`),
join(requirePath, `${name}.scss.map`) // with source map
]))

// Replaces source component '*.yaml' with:
// - `fixtures.json` fixtures for tests
// - `macro-options.json` component options
Expand Down
25 changes: 19 additions & 6 deletions shared/tasks/styles.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,25 @@ export async function compileStylesheet ([modulePath, { srcPath, destPath, fileP
let css
let map

// Configure PostCSS
/**
* Configure PostCSS
*
* @type {import('postcss').ProcessOptions}
*/
const options = {
from: moduleSrcPath,
to: moduleDestPath
to: moduleDestPath,

/**
* Always generate source maps for either:
*
* 1. PostCSS on Sass compiler result
* 2. PostCSS on Sass sources (Autoprefixer only)
*/
map: {
annotation: true,
inline: false
}
}

// Compile Sass to CSS
Expand Down Expand Up @@ -79,10 +94,8 @@ export async function compileStylesheet ([modulePath, { srcPath, destPath, fileP
}))

// Pass source maps to PostCSS
options.map = {
annotation: true,
inline: false,
prev: map
if (typeof options.map === 'object') {
options.map.prev = map
}
}

Expand Down

0 comments on commit b7acb29

Please sign in to comment.