Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USWDS-Compile: Support configuring sass-embedded #145

Draft
wants to merge 6 commits into
base: dw-gulp-sass-update
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ Use path settings to customize where USWDS Compile looks for USWDS source and ou

### Additional settings

| Setting | Default | Description |
| --------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sprite.projectIconsOnly` | `false` | Include _only_ the icons in `paths.src.projectIcons` in the icon sprite. |
| `settings.compile.browserslist` | `["> 2%", "last 2 versions", "IE 11", "not dead"]` | Define the [browserslist query](https://github.com/browserslist/browserslist?tab=readme-ov-file#queries) for CSS prefixes generated by [autoprefixer](https://github.com/postcss/autoprefixer). |
| `settings.compile.sassSourcemaps` | `true` | Include sourcemap when compiling SASS to CSS. |
| `settings.compile.sassDeprecationWarnings` | `false` | Show USWDS Sass deprecation warnings. When set to `true`, Sass will output deprecation warnings for USWDS code in the terminal during compilation. Deprecation warnings for non-USWDS Sass will output even when this value is set to `false`. |
| Setting | Default | Description |
| --------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sprite.projectIconsOnly` | `false` | Include _only_ the icons in `paths.src.projectIcons` in the icon sprite. |
| `settings.compile.browserslist` | `["> 2%", "last 2 versions", "IE 11", "not dead"]` | Define the [browserslist query](https://github.com/browserslist/browserslist?tab=readme-ov-file#queries) for CSS prefixes generated by [autoprefixer](https://github.com/postcss/autoprefixer). |
| `settings.compile.sassSourcemaps` | `true` | Include sourcemap when compiling SASS to CSS. |
| `settings.compile.sassOptions` | `{quietDeps: true, style: "compressed"}` | Configure [sass-embedded options](https://sass-lang.com/documentation/js-api/interfaces/options/). By default SASS deprecation warnings arising from USWDS source are hidden and output CSS is minified. These options can be overridden and additional options specified. When `loadPaths` is defined, the paths are appended to those necessary for USWDS compilation. The `watch` script will also watch these directories for changes. |

### Functions

Expand Down
32 changes: 28 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ let settings = {
},
browserslist: ["> 2%", "last 2 versions", "IE 11", "not dead"],
sassSourcemaps: true,
sassDeprecationWarnings: false,
/**
* @type {boolean | undefined}
* @deprecated Set `sassOptions.quietDeps` instead. */
sassDeprecationWarnings: undefined,
/**
* @type {import('sass-embedded').Options<"async">}
* @default
* {
* quietDeps: true,
* style: "compressed"
* }
*/
sassOptions: {},
},
sprite: {
width: 24,
Expand Down Expand Up @@ -176,7 +188,9 @@ function buildSass() {
grid: true,
overrideBrowserslist: settings.compile.browserslist,
}),
csso({ forceMediaMerge: false }),
...(settings.compile.sassOptions.style === "expanded"
? []
: [csso({ forceMediaMerge: false })]),
],
includes: [
// 1. local theme files
Expand All @@ -196,8 +210,15 @@ function buildSass() {
.pipe(
sass({
style: "compressed",
loadPaths: buildSettings.includes,
quietDeps: !settings.compile.sassDeprecationWarnings,
...settings.compile.sassOptions,
loadPaths: [
...buildSettings.includes,
...(settings.compile.sassOptions.loadPaths ?? []),
],
quietDeps:
settings.compile.sassDeprecationWarnings !== undefined
? !settings.compile.sassDeprecationWarnings
: settings.compile.sassOptions.quietDeps ?? true,
}).on("error", handleError)
)
.pipe(replace(/\buswds @version\b/g, `based on uswds v${pkg}`))
Expand All @@ -214,6 +235,9 @@ function watchSass() {
[
`${paths.dist.theme}/**/*.scss`.replace("//", "/"),
`${paths.src.projectSass}/**/*.scss`.replace("//", "/"),
...(settings.compile.sassOptions.loadPaths ?? []).map((loadPath) =>
`${loadPath}/**/*.scss`.replace("//", "/")
),
],
buildSass
);
Expand Down
Loading