【问题标题】:Compile only needed sass file whit grunt用 grunt 编译只需要的 sass 文件
【发布时间】:2017-06-04 07:50:53
【问题描述】:

使用 contrib-sass 和 contrib-watching 我只想编译需要的文件,因为我在生产服务器上有很多 scss 文件。

我写了这个 Gruntfile,但有些东西不起作用。看着工作,但什么也不编译。

module.exports = function(grunt) {

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    watch: {
     sass: {
         files: [
             'sites/**/scss/*.scss'
         ],
         tasks: ['sass'],
         options: {
             spawn: false
         }
     }
  },

  sass: {
    dist:{
      options: {
          style: 'compressed'
      },
      files: objDestSource
    }
  }

});

// On watch events configure jshint:all to only run on changed file
grunt.event.on('watch', function(action, filepath) {
  var filepath_scss = filepath;
  var filepath_css = filepath.replace("scss", "css");
  filepath_css = filepath_css.replace("scss", "css");
  filepath= '\''+filepath_css+'\' : \''+filepath_scss+'\'';
  console.log(filepath);
  grunt.config('sass.dist.files', filepath);
});

grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default',['watch']);

};

【问题讨论】:

    标签: javascript sass gruntjs watch


    【解决方案1】:

    我解决了。 这是我的脚本代码:

    module.exports = function(grunt) {

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
    
        watch: {
         sass: {
             files: [
                 'pippo/*/scss/*.scss',
                 'pippo/test/*/scss/*.scss'
             ],
             tasks: ['sass'],
             options: {
                 spawn: false
             }
         }
      },
    
      sass: {
        dist:{
          options: {
              style: 'compressed'
          },
          files: {
            'pippo/test/statics/css/ie.css' : 'pippo/test/statics/scss/ie.scss'
          }
        }
      }
    
    });
    
    grunt.event.on('watch', function(action, filepath) {
      var filepath_scss = filepath;
      var filepath_css = filepath.replace("scss", "css");
      filepath_css = filepath_css.replace("scss", "css");
      var finalpath = {};
      finalpath[filepath_css] = filepath_scss;
      grunt.config('sass.dist.files', finalpath );
    });
    
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default',['watch']);
    

    };

    【讨论】:

      猜你喜欢
      • 2014-05-04
      • 2015-01-02
      • 2018-08-22
      • 2017-03-16
      • 1970-01-01
      • 2017-04-16
      • 2014-03-04
      • 2017-08-07
      • 2019-04-26
      相关资源
      最近更新 更多