在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):dlmanning/gulp-sass开源软件地址(OpenSource Url):https://github.com/dlmanning/gulp-sass开源编程语言(OpenSource Language):JavaScript 91.5%开源软件介绍(OpenSource Introduction):gulp-sassSass plugin for Gulp. Before filing an issue, please make sure you have updated to the latest version of Migrating your existing project to version 5? Please read our (short!) migration guide. SupportOnly Active LTS and Current releases are supported. InstallationTo use Whichever compiler you choose, it's best to install these as dev dependencies: npm install sass gulp-sass --save-dev Importing it into your project
const sass = require('gulp-sass')(require('sass')); To use import dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass); UsageNote: These examples are written for CommonJS modules and assume you're using Gulp 4. For examples that work with Gulp 3, check the docs for an earlier version of
Render your CSSTo render your CSS with a build task, then watch your files for changes, you might write something like this: 'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
};
exports.buildStyles = buildStyles;
exports.watch = function () {
gulp.watch('./sass/**/*.scss', ['sass']);
}; With synchronous rendering, that Gulp task looks like this: function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sass.sync().on('error', sass.logError))
.pipe(gulp.dest('./css'));
}; Render with optionsTo change the final output of your CSS, you can pass an options object to your renderer.
For example, to compress your CSS, you can call function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
};
exports.buildStyles = buildStyles; Or this for synchronous rendering: function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sass.sync({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./css'));
};
exports.buildStyles = buildStyles; Include a source map
const sourcemaps = require('gulp-sourcemaps');
function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./css'));
}
exports.buildStyles = buildStyles; By default, const sourcemaps = require('gulp-sourcemaps');
function buildStyles() {
return gulp.src('./sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('./css'));
};
exports.buildStyles = buildStyles; Migrating to version 5
Setting a Sass compilerAs of version 5, npm install sass gulp-sass --save-dev Then, you must explicitly set that compiler in your gulpfille. Instead of setting a These changes look something like this: - const sass = require('gulp-sass'));
- const compiler = require('sass');
- sass.compiler = compiler;
+ const sass = require('gulp-sass')(require('sass')); If you're migrating an ECMAScript module, that'll look something like this: import dartSass from 'sass';
- import sass from 'gulp-sass';
- sass.compiler = dartSass;
import dartSass from 'sass';
+ import gulpSass from 'gulp-sass';
+ const sass = gulpSass(dartSass); What about fibers?We used to recommend Node fibers as a way to speed up asynchronous rendering with Dart Sass. Unfortunately, Node fibers are discontinued and will not work in Node.js 16. The Sass team is exploring its options for future performance improvements, but for now, you will get the best performance from Issues
If you have a feature request/question about how Sass works/concerns on how your Sass gets compiled/errors in your compiling, it's likely a Dart Sass or LibSass issue and you should file your issue with one of those projects. If you're having problems with the options you're passing in, it's likely a Dart Sass or Node Sass issue and you should file your issue with one of those projects. We may, in the course of resolving issues, direct you to one of these other projects. If we do so, please follow up by searching that project's issue queue (both open and closed) for your problem and, if it doesn't exist, filing an issue with them. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论