gpt4 book ai didi

sass - Gulp:如何一起使用 Browsersync、Sourcemaps、Autoprefixer 和 CSS Cleaner?

转载 作者:行者123 更新时间:2023-12-04 15:20:03 32 4
gpt4 key购买 nike

见下文。我当前代码遇到的问题是 Sourcemap 没有通过 Browsersync 注入(inject)。我在这里遗漏了什么还是做错了?

以供引用:
https://www.browsersync.io/docs/gulp/#gulp-sass-maps

// requirements
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var browserSync = require('browser-sync').create();
var prefix = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var cssclean = require('gulp-clean-css');

// create sass tasks
gulp.task('sass', function() {
return sass('assets/scss/style.scss', {sourcemap: true, style: 'compact'})
.on('error', function (err) {
console.error('Error!', err.message);
})
.pipe(rename({suffix: '.min'}))
.pipe(cssclean())
.pipe(prefix("last 2 versions", "> 1%", "ie 8", "Android 2", "Firefox ESR"))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('assets/styles'))
.pipe(browserSync.stream({match: '**/*.css'}))
});

gulp.task('serve', ['sass'], function() {

browserSync.init({
proxy: "localhost/portfolio2014",
open:false
});

gulp.watch("assets/scss/**/*.scss", ['sass']);
gulp.watch(["assets/styles/*.css", "site/**/*", "content/**/*", "assets/javascript/*.js"]).on('change', browserSync.reload);
});

// default task (just run gulp)
gulp.task('default', ['serve'] );

最佳答案

你必须使用gulp-ruby-sass ?下面的 gulpfile.js 使用 gulp-sass 添加源映射并在保存带有源映射的 .scss 文件时更新浏览器。

        var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var prefix = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var cssclean = require('gulp-clean-css');

// create sass tasks
gulp.task('sass', function () {
return gulp.src('assets/scss/test.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(rename({ suffix: '.min' }))
.pipe(cssclean())
.pipe(prefix("last 2 versions", "> 1%", "ie 8", "Android 2", "Firefox ESR"))
.pipe(sourcemaps.write(''))
.pipe(gulp.dest('assets/styles'))
.pipe(browserSync.stream({ match: '**/*.css' }))
.on('error', function (err) {
console.error('Error!', err.message);
});
});

gulp.task('serve', ['sass'], function () {

browserSync.init({
proxy: "localhost/portfolio2014",
open: false
});

gulp.watch("assets/scss/**/*.scss", ['sass']);
gulp.watch(["assets/styles/*.css", "assets/javascript/*.js"]).on('change', browserSync.reload);
});

// default task (just run gulp)
gulp.task('default', ['serve']);

关于sass - Gulp:如何一起使用 Browsersync、Sourcemaps、Autoprefixer 和 CSS Cleaner?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36046162/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com