Mac 安装 Grunt

2019-11-06  本文已影响0人  HopeLii

安装brew

打开http://brew.sh/登陆brewhome官网,上面有安装命令。

安装node

brew install node

安装grunt

npm install -g grunt-cli

安装grunt以及插件

  1. 打开项目目录,输入npm init
  2. 安装grunt, npm install grunt --save-dev
  3. 在当目录创建 Gruntfile.js文件,配置文件结构如下
    官方文档 https://gruntjs.com/sample-gruntfile
module.exports = function(grunt) {

  grunt.initConfig({
    jshint: {
      files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },
    watch: {
      files: ['<%= jshint.files %>'],
      tasks: ['jshint']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('default', ['jshint']);

};
  1. 打开https://gruntjs.com/plugins,安装需要自己所需要的插件,或者打开https://www.npmjs.com/search?q=grunt也能找到插件
安装sass

mac自带ruby,所以直接在命令行输入。安装成功后,才能正常运行grunt的sass插件

sudo gem install -n /usr/loca/bin sass
上一篇 下一篇

猜你喜欢

热点阅读