Peter Isaac
Peter Isaac

Reputation: 372

How to ignore source folder structure in gulp-sass?

I am trying to make "main.css" file to be directly in css folder. However, I get this path "/css/Content/scss/main.css" and I want "/css/main.css"

gulp.task('sass', () => {
    const sourceFolder = path.join('.', 'Content', 'scss', 'main.scss');
    const distFolder = path.join('.', 'wwwroot', 'css');
    return gulp.src(sourceFolder)
        .pipe(sass({
            sourceMap: true,
            style: 'compressed'
        }))
        .pipe(cleanCSS({
            compatibility: 'ie8'
        }))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(distFolder))
        .on('end', () => console.log(`[${new Date().toLocaleTimeString()}] -> sass compilation complete...`));
});

Upvotes: 0

Views: 285

Answers (1)

Mark
Mark

Reputation: 180765

Assuming you want main.css to end up in wwwroot/css try changing to this line:

return gulp.src(sourceFolder, { base: path.join('Content', 'scss') })

Sorry but I cannot explain why your original code works on Linux.

From glob base in gulpjs.docs:

Vinyl instances generated by src() are constructed with the glob base set as their base property. When written to the file system with dest(), the base will be removed from the output path to preserve directory structures.

So with the base set as path.join('Content', 'scss') that portion of the filepath will be removed, thus main.css will go directly into your distFolder with the parent folders removed.

Upvotes: 1

Related Questions