Compile SCSS Using the Sass CLI
The Sass command-line interface accepts source and destination paths. The source may be a single SCSS file or a directory of Sass files.
The basic form is sass input.scss output.css. You can also compile a directory recursively using sass src/scss:public/css, allowing Sass to generate CSS for stylesheet entry points in the source directory.
Common options include:
--watch: Recompile when source files change.--style=expanded: Produce readable CSS with expanded formatting.--style=compressed: Minify the generated CSS.--no-source-map: Disable source-map generation.
Directory compilation does not mean every file is necessarily intended to be a standalone stylesheet. Partial files and entry points should be organized carefully to avoid emitting unnecessary CSS files.
Keep the watcher running while editing SCSS. For production, use a reproducible build command rather than relying on a manually running watcher.
npx sass src/scss/main.scss public/css/main.css
npx sass --watch src/scss:public/css
npx sass --style=compressed src/scss/main.scss public/css/main.min.css
npx sass --no-source-map src/scss/main.scss public/css/main.cssWhich CLI option automatically recompiles Sass files when they change?