Created
February 1, 2022 10:33
-
-
Save joneff/29ca55a4942e6efea633b5f99462ba96 to your computer and use it in GitHub Desktop.
Compile sass files with ~
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const gulp = require('gulp'); | |
const sass = require('gulp-sass')(require('sass')); | |
// An importer that redirects relative URLs starting with "~" to | |
// `node_modules`. | |
function packageImporter(url) { | |
// If the doesn't start with ~, return it as is. | |
if (!url.startsWith('~')) { | |
return null; | |
} | |
const nodeModules = path.resolve('./node_modules'); | |
// Create a new url to the correct location | |
const file = path.resolve( | |
nodeModules, | |
url.slice(1) | |
); | |
return { file }; | |
} | |
gulp.task('sass', function () { | |
return gulp.src('./sass/**/*.scss') | |
.pipe(sass({ importer: [packageImporter]}).on('error', sass.logError)) | |
.pipe(gulp.dest('./wwwroot/css')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment