Gulp-从节点 - sass迁移到sass for angular.js

发布于 2025-02-10 03:58:49 字数 2097 浏览 1 评论 0原文

我们有一个Angular.js项目,我们使用Gulp。

我正在尝试摆脱node-sass,因为它已将其弃用sass

是Angular.js与Sass

Node版本兼容:15

我们在这里如何使用Node-sass

'use strict';

var gulp = require('gulp');
var paths = gulp.paths;
var $ = require('gulp-load-plugins')();

// TODO: node-sass is deprecated; replace with
// dart-sass (https://sass-lang.com/dart-sass)
$.sass.compiler = require('node-sass');

gulp.task('styles', function () {

  var injectFiles = gulp.src([
    paths.src + '/{app,components}/**/*.scss',
    '!' + paths.src + '/app/index.scss',
    '!' + paths.src + '/app/vendor.scss'
  ], { read: false });

  var injectOptions = {
    transform: function(filePath) {
      filePath = filePath.replace(paths.src + '/app/', '');
      filePath = filePath.replace(paths.src + '/components/', '../components/');
      return '@import \'' + filePath + '\';';
    },
    starttag: '// injector',
    endtag: '// endinjector',
    addRootSlash: false
  };

  // "Enables you to work on a subset of the original files by filtering them
  // using glob patterns. When you're done and want all the original files back,
  // you just use the restore stream"
  var indexFilter = $.filter(paths.src + '/app/index.scss', {restore: true});

  return gulp.src([
      paths.src + '/app/index.scss', // A template, empty except for the injection target
      paths.src + '/app/vendor.scss' // Currently not used
    ], {allowEmpty: true})
    .pipe(indexFilter)
    .pipe($.inject(injectFiles, injectOptions)) // injects the @import's to all app and component scss
    .pipe(indexFilter.restore)
    .pipe($.sass().on('error', $.sass.logError)) // compiles index.scss (and vendor.scss if existent)
    .pipe($.autoprefixer()
      .on('error', function handleError(err) {
        console.error(err.toString());
        this.emit('end');
      })
    )
    .pipe(gulp.dest(paths.tmp + '/serve/app/'));
});

我的尝试迁移

删除node-sass并安装sass 构建编译器

$.sass.compiler = require('sass');

然后用SASS应用程序不再

we have an Angular.JS project and we using Gulp.

I am trying to get out of node-sass as its deprecated to dart sass

is angular.js compatible with sass

Node version : 15

here how we are using the node-sass

'use strict';

var gulp = require('gulp');
var paths = gulp.paths;
var $ = require('gulp-load-plugins')();

// TODO: node-sass is deprecated; replace with
// dart-sass (https://sass-lang.com/dart-sass)
$.sass.compiler = require('node-sass');

gulp.task('styles', function () {

  var injectFiles = gulp.src([
    paths.src + '/{app,components}/**/*.scss',
    '!' + paths.src + '/app/index.scss',
    '!' + paths.src + '/app/vendor.scss'
  ], { read: false });

  var injectOptions = {
    transform: function(filePath) {
      filePath = filePath.replace(paths.src + '/app/', '');
      filePath = filePath.replace(paths.src + '/components/', '../components/');
      return '@import \'' + filePath + '\';';
    },
    starttag: '// injector',
    endtag: '// endinjector',
    addRootSlash: false
  };

  // "Enables you to work on a subset of the original files by filtering them
  // using glob patterns. When you're done and want all the original files back,
  // you just use the restore stream"
  var indexFilter = $.filter(paths.src + '/app/index.scss', {restore: true});

  return gulp.src([
      paths.src + '/app/index.scss', // A template, empty except for the injection target
      paths.src + '/app/vendor.scss' // Currently not used
    ], {allowEmpty: true})
    .pipe(indexFilter)
    .pipe($.inject(injectFiles, injectOptions)) // injects the @import's to all app and component scss
    .pipe(indexFilter.restore)
    .pipe($.sass().on('error', $.sass.logError)) // compiles index.scss (and vendor.scss if existent)
    .pipe($.autoprefixer()
      .on('error', function handleError(err) {
        console.error(err.toString());
        this.emit('end');
      })
    )
    .pipe(gulp.dest(paths.tmp + '/serve/app/'));
});

my tries to migrate

remove node-sass and install sass
then replace the the compiler with sass

$.sass.compiler = require('sass');

app is not building anymore

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中性美 2025-02-17 03:58:49

我想如何使它

取代

var sass = require('gulp-sass'));
var compiler = require('sass');
sass.compiler = compiler;

 var sass = require('gulp-sass')(require('sass'));

这样的情况

....
.pipe(sass().on('error', sass.logError))
....

I figure how to make it

replace

var sass = require('gulp-sass'));
var compiler = require('sass');
sass.compiler = compiler;

with

 var sass = require('gulp-sass')(require('sass'));

to be like this in my case

....
.pipe(sass().on('error', sass.logError))
....
飘逸的'云 2025-02-17 03:58:49

您还可以使用poStrequirEtransForms属性来配置gulp-sass使用dart-sass(在NPM)。

更改:

var $ = require('gulp-load-plugins')();

当时

var $ = require('gulp-load-plugins')({
  postRequireTransforms: {
    // Use dart-sass as the compiler for gulp-sass.
    sass: function(gulpSass) {
      return gulpSass(require('sass'));
    }
  }
});

可以像往常一样使用插件属性sass()$。sass()

You can also use use the postRequireTransforms property to configure gulp-sass to use dart-sass (called sass in npm).

Change:

var $ = require('gulp-load-plugins')();

to

var $ = require('gulp-load-plugins')({
  postRequireTransforms: {
    // Use dart-sass as the compiler for gulp-sass.
    sass: function(gulpSass) {
      return gulpSass(require('sass'));
    }
  }
});

Then can use the plugin property sass() as usual. $.sass().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文