grunt自动编译:命令 grunt watch
Gruntfile.js:
1 module.exports = function(grunt) { 2 3 // Project configuration. 4 grunt.initConfig({ 5 6 //Read the package.json (optional) 7 pkg: grunt.file.readJSON('package.json'), 8 9 // Metadata. 10 meta: { 11 basePath: '../', 12 srcPath: '../assets/sass/', 13 deployPath: '../assets/css/' 14 }, 15 16 banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + 17 '<%= grunt.template.today("yyyy-mm-dd") %> ' + 18 '* Copyright (c) <%= grunt.template.today("yyyy") %> ', 19 20 // Task configuration. 21 sass: { 22 dist: { 23 files: { 24 '<%= meta.deployPath %>test.css': '<%= meta.srcPath %>test.scss' 25 }, 26 options: { 27 sourcemap: 'true' 28 } 29 } 30 }, 31 watch: { 32 scripts: { 33 files: [ 34 '<%= meta.srcPath %>/**/*.scss' 35 ], 36 tasks: ['sass'] 37 } 38 } 39 }); 40 41 // These plugins provide necessary tasks. 42 grunt.loadNpmTasks('grunt-contrib-sass'); 43 grunt.loadNpmTasks('grunt-contrib-watch'); 44 45 // Default task. 46 grunt.registerTask('default', ['sass']); 47 };
package.json:
1 { 2 "name": "gruntSass", 3 "version": "0.0.1", 4 "devDependencies": { 5 "grunt": "0.4.1", 6 "grunt-contrib-watch": "0.4.3", 7 "grunt-contrib-sass": "0.4.0" 8 } 9 }
原址:http://www.w3cplus.com/preprocessor/nodejs-and-grunt-compile-sass-to-css.html
coffee自动编译:coffee --watch --compile experimental.coffee
原址:http://coffee-script.org/
sass自动编译:sass --watch app/sass:public/stylesheets
原址:http://sass-lang.com/guide