javascript - Node.js 通过 Grunt 运行 SASS 预处理器

标签 javascript ruby node.js sass gruntjs

我有 D:/projectA

Gruntfile.js

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({

    //Read the package.json (optional)
    pkg: grunt.file.readJSON('package.json'),

    // Metadata.
    meta: {
        basePath: '../',
        srcPath: '../',
        deployPath: '../'
    },

    banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
            '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
            '* Copyright (c) <%= grunt.template.today("yyyy") %> ',

    // Task configuration.
    concat: {
        options: {
            stripBanners: true
        },
        dist: {
            src: ['<%= meta.srcPath %>engine/css/mycss1.css', '<%= meta.srcPath %>engine/css/mycss2.css'],
            dest: '<%= meta.deployPath %>engine/css/00myfinal.css'
        }
    },

    //the Sass Task 
    sass: {
        sass_my_files : {

            files : {
                //"the Destination " : " the source files"
                "../engine/css/mystyle3.css" : "../engine/css/mysass1.scss",
            },
            options : {
                "style":"compressed",
                "precision":"7"
            },
        },
    },

});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-sass');

// Default task
grunt.registerTask('default', ['concat','sass']);

};

package.json

{
  "name": "Test-Project",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "~0.1.3"
  }
}

Ruby 安装在我的“Windows”上。

插入以下命令:

npm install ruby-sass

我把一切都搞定了。但是在运行“Grunt”命令时,我收到错误:

You need to have Ruby and Sass installed and in your path for this task to work.

有人可以告诉我为什么我的控制台在成功运行“concat”任务后显示错误,并在“SASS<”上显示错误/em>'任务?

最佳答案

使用npm install -g ruby​​-sass,它会在环境变量中全局安装 ruby​​-sass gem。然后继续。

我建议使用 Gulp 而不是 Grunt。它们的功能相似,但我更喜欢 Gulp,因为它的管道 Assets 。确实值得学习。

关于javascript - Node.js 通过 Grunt 运行 SASS 预处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33128133/

相关文章:

javascript - 使用 javascript 提取当前 img src 值

javascript - 调用 Node SparkPost API 时在替换数据中发送 "CC"和 "BCC"

ruby - 跟踪 Ruby 中的代码?

ruby - Chef12 到 Chef13 升级中的路径问题

node.js - 数据库中的 HTML 显示为纯文本

javascript - 如何使用 native react 在另一个屏幕上发送并显示文本输入的值?

javascript - 使用相同的 jQuery 函数在不同的 html 元素类型上设置值

javascript - Mongodb 查询 - 和条件

ruby - 限制 ruby​​ 文件流的速率

.net - SQL Server 数据库插入/更新 TCP 通知