Skip to content

Instantly share code, notes, and snippets.

@joneff
Created February 1, 2022 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joneff/29ca55a4942e6efea633b5f99462ba96 to your computer and use it in GitHub Desktop.
Save joneff/29ca55a4942e6efea633b5f99462ba96 to your computer and use it in GitHub Desktop.
Compile sass files with ~
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