配置咕噜的化身,Haml的,无礼的话在GitHub上的页面

问题描述 投票:2回答:1

我试图用化身,Haml的,萨斯跑我的开发/原型环境(不是博客),并将其托管在GitHub上的页面。

在当地,我使用Grunt.js编译HAML,SASS和服务/构建哲基尔。

虽然我的Gruntfile.js能够做我的工作,它作为我尝试运行构建并兼任是非常缓慢的。

任何咕噜专家能指点如何优化我的步兵配置,因此它可以运行得更快朝着正确的方向?谢谢!

下面是我目前的配置:

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

jekyll: {
  options: {                          
    src : './',
    dest: './_gh_pages',
    config: '_config.build.yml'       // avoid the relative baseurl issue
  },

  serve: {
    options: {
      serve: true,
      port: 9001
    }
  },

  dev: {

  }
},

compass: {
  dev: {
    options: {
      config: 'config.rb',
      force: true
    }
  }
},

haml: {
  includes: {
    expand: true,
    cwd: 'haml/includes/',
    src: ['*.haml'],
    dest: '_includes/',
    ext: '.html'
  },
  layouts: {
    expand: true,
    cwd: 'haml/layouts/',
    src: ['*.haml'],
    dest: '_layouts/',
    ext: '.html'
  },
  pages: {
    expand: true,
    cwd: 'haml/',
    src: ['*.haml'],
    dest: './',
    ext: '.html'
  }
},    

watch: {
  options: {
    atBegin: true
  },
  sass: {
    files: ['sass/**/*.scss'],
    tasks: ['compass:dev']
  },
  haml: {
    files: ['haml/**/*.haml'],
    tasks: ['haml:includes', 'haml:layouts', 'haml:pages']
  },
  jekyll: {
    files: ['./**/*.html', './**/*.css'],
    tasks: ['jekyll:dev']
  }
},
concurrent: {
  target: {
    tasks: ['jekyll:serve', 'watch'],
    options: {
      logConcurrentOutput: true
    }
  }
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-html-validation');
grunt.loadNpmTasks('grunt-jekyll');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-haml');
grunt.loadNpmTasks('grunt-concurrent');

grunt.registerTask('default', ['concurrent:target']);
sass haml gruntjs jekyll github-pages
1个回答
4
投票

我还没有Grunthaml使用jekyll,我却用它每天的基础上管理多个项目,采用不同的包装需要。

这很难说,你的应用是多么复杂或有多大只要看一眼你的Gruntfile.js,但我肯定会通过使任务更聪明一点开始。该watch任务通常是一个我把大部分注意力,因为这是最好应在保存文件运行的唯一任务。例如,如果您保存.scss文件,只有compass:dev任务解雇了。如果保存.js文件,任务jshintjasmineuglify:dev会火起来。这令发展轮只在需要的地方转弯,和Grunt完成任务快。

我没有在你的Gruntfile.js看到另一件事是devdist专门任务,它可以是一个很好的做法。一个例子:

// Start web server
grunt.registerTask('serve', [
    'connect:livereload',
    'watch'
]);

// Compile production files
grunt.registerTask('dist', [
    'jshint',
    'jasmine',
    'uglify:dist',
    'compass:dist'
]);

// Compile developer friendly environment
grunt.registerTask('dev', [
    'jshint',
    'jasmine',
    'uglify:dev',
    'compass:dev',
    'connect:livereload'
]);

// Default task(s).
grunt.registerTask('default', 'dev’);

使用$ grunt serve一个外壳启动本地服务器,并观看应用。为了充分建立不依赖于watch任务,运行$ grunt作出充分的dev版本(因为这是默认的任务在这个例子中)或运行$ grunt dist使生产就绪的构建。

所以我的建议是依靠在开发watch任务,并运行做它,所有谨慎的任务。 Grunt的美不仅在多任务处理能力,同时也对任务点播。运行完全建立在每一个文件的保存是可能的,但效率不高。

BTW,jekyll在您watch任务是空的,因为jekyll:dev是空的:

jekyll: {
    files: ['./**/*.html', './**/*.css'],
    tasks: ['jekyll:dev']
}

希望能帮助到你!

© www.soinside.com 2019 - 2024. All rights reserved.