uswds / uswds-compile

Simple Gulp 5 functions for copying USWDS static assets and transforming USWDS Sass into browser-readable CSS.
Other
20 stars 13 forks source link

USWDS-Compile - Bug: Sourcemaps have incorrect path #61

Closed LeraAtwater closed 11 months ago

LeraAtwater commented 1 year ago

Describe the bug

Sourcemaps are compiled correctly and display in the browser inspection tool. However, the directory it points to is incorrect.

For example, the sass files are located at: /custom/samhsa_data/sass/partial/_home-page2.scss

The sourcemap describes the location as: /custom/samhsa_data/css/partial/_home-page2.scss

The /css directory is the location for compiled style on this site, there are no sass files anywhere in that directory.

Steps to reproduce the bug

  1. Compile sass using uswds-compile
  2. Using browser dev tool, look at the location of sass files

Expected Behavior

Sourcemap should accurately reflect which directory the sass files come from

Related code

Gulpfile for this project-- nothing special going on outside the defaults

/* gulpfile.js */

const uswds = require("@uswds/compile");

/**
 * USWDS version
 */

uswds.settings.version = 3;

/**
 * Path settings
 * Set as many as you need
 */

 uswds.paths.dist.theme =   "./sass"    // Project destination for theme files (Sass entry point and settings)
 uswds.paths.dist.img = "./assets/img"  // Project destination for images
 uswds.paths.dist.fonts =   "./assets/fonts"    // Project destination for fonts
 uswds.paths.dist.js =  "./assets/js"   // Project destination for compiled JavaScript
 uswds.paths.dist.css = "./css" // Project destination for compiled CSS
 uswds.sprite.projectIconsOnly =    false

 /**
  * Exports
  * Add as many as you need
  */

  exports.compile = uswds.compile;
  exports.watch = uswds.watch;
  exports.init = uswds.init;
  exports.update = uswds.updateUswds;
  exports.default = uswds.watch;

Screenshots

Wrong path displayed in browser dev tool:

Screenshot 2023-06-13 at 12 48 57

System setup

USWDS compile version: 1.0 USWDS version: 3.5 Mac OS (Ventura) Chrome browser, latest version

Additional context

No response

Code of Conduct

mejiaj commented 11 months ago

Confirmed this bug via uswds/uswds-sandbox repo.


The CSSO plugin (postcss-csso) combined with writing map to a file seems to be causing the incorrect paths.

Workarounds

  1. Disable CSSO plugin. Increases CSS file size [521KB → 552KB].
  2. Use inline sourcemap. Drastically increases CSS file size [521KB → 1.9MB].
  3. CSSO + SASS compressed. Fixes paths, speeds up builds by 0.2ms, and leaner CSS.

Full table

Build task CSS size Build time Paths fixed
Defaults 521KB 4.73s
CSSO with forceMediaMerge 505KB 4.64s n/a
CSSO + SASS compressed 521KB 4.57s
SASS, no compression. CSSO Disabled. 723KB 3.91s
SASS compressed 552KB 3.9s

Other things I've tried

  1. Passing base SASS directory after gulp.src paths.
  2. Passing source to sourcemaps.write().