gulp-glob-sass
v1.0.3
Published
The gulpSassGlob plugin simplifies working with SASS/SCSS files by automatically replacing @import, @use, and @forward constructs using templates with an actual list of matching files. This helps automate and simplify the inclusion of style files in proje
Readme
Guide to Using the gulpGlobSass Plugin
The plugin simplifies working with SASS/SCSS files by automatically replacing @import, @use, and @forward constructions that use glob patterns with an actual list of matching files. This helps automate and streamline the process of including style files in projects. Based on gulp-sass-glob plugin. Added support for @use and @forward. Added base directory setting.
Installation
- Download the plugin.
- Install the required dependencies (It will be automatic):
npm install gulp-glob-sass -D- Include the plugin in your project.
Usage
- Import the plugin:
const gulpGlobSass = require('gulp-glob-sass');- Example Gulp task:
const gulp = require('gulp');
const gulpGlobSass = require('gulp-glob-sass');
const sass = require('gulp-sass')(require('sass')); // Example with Gulp Sass
gulp.task('styles', () => {
return gulp.src('src/**/*.scss') // Path to SASS/SCSS files
.pipe(gulpGlobSass({
baseDir: __dirname, // Base directory (default is process.cwd())
includePaths: ['src/styles'], // Paths to search for files
ignorePaths: ['**/_ignore.scss'] // Ignored files
}))
.pipe(sass()) // Compile SCSS to CSS
.pipe(gulp.dest('dist')); // Output folder
});Configuration
You can customize the plugin's behavior by passing a configuration object to gulpSassGlob.
Available Options:
baseDir(string, default isprocess.cwd()):- Specifies the base directory for file searches.
- Example:
baseDir: __dirname.
includePaths(array of strings, default is empty):- Additional paths to search for files.
- Example:
includePaths: ['src/styles', 'node_modules'].
ignorePaths(array of strings, default is empty):- Paths or file patterns to ignore.
- Example:
ignorePaths: ['**/_ignore.scss', '**/temp/*.scss'].
Examples
Example 1: Automatic File Inclusion
If the main.scss file contains the line:
@use "components/*";The plugin will replace it with:
@use "components/button.scss";
@use "components/header.scss";
@use "components/footer.scss";(The file list is generated automatically based on the contents of the components directory.)
Example 2: Ignoring Files
With the configuration:
ignorePaths: ['**/_ignore.scss']Files matching the pattern will not be included in the import list.
Example 3: Working with SASS
If the file has a .sass extension, the plugin will generate lines without a semicolon:
@use "components/button"
@use "components/header"Advantages
- Automation: Eliminates the need to manually list imported files.
- Glob Pattern Support: Flexible file inclusion using masks.
- Customizable: Allows ignoring specific files or specifying additional paths.
- Cross-Platform: Ensures correct path handling regardless of the OS.
Compatibility
The plugin is compatible with:
- Gulp (version 4 and above).
- Files with
.scssand.sassextensions.
Possible Errors
File Not Found:
- Check the glob pattern for correctness.
- Ensure the paths in
includePathsare specified correctly.
Incorrect Syntax:
- Make sure
.sassfiles do not use semicolons, and.scssfiles do.
- Make sure
