- 介绍
- 压缩js代码
- 合并js文件
- 单元测试
- js代码检查
- 监控文件修改重启任务
- 命令
- grunt dist
- grunt watch
- grunt test
- grunt docs
- grunt 重新构建所有内容并运行测试用例
- 安装
-
grunt模块以grunt-contrib-开头
- npm i -g grunt grunt-init grunt-cli
- 例子
- o→
- // Gruntfile.js
- module.exports = function (grunt) {
- grunt.loadNpmTasks(‘grunt-contrib-clean’)
- grunt.loadNpmTasks(‘grunt-contrib-concat’)
- grunt.loadNpmTasks(‘grunt-contrib-jshint’)
- grunt.loadNpmTasks(‘grunt-contrib-uglify’)
- grunt.loadNpmTasks(‘grunt-replace’)
- grunt.initConfig({
- pkg: grunt.file.readJSON(‘package.json’),
- jshint: {
- all: {
- src: [‘Gruntfile.js’, ‘src//*.js’, ‘test//*.js’],
- options: {
- }
- }
- },
- clean: [‘lib’],
- concat: {
- htmlhint: {
- src: [‘src/core.js’, ‘src/reporter.js’, ‘src/htmlparser.js’, ‘src/rules/*.js’],
- dest: ‘lib/htmlhint.js’
- }
- },
- uglify: {
- htmlhint: {
- options: {
- banner: ‘a’,
- beautify: {
- }
- },
- files: {
- ‘lib/<%= pkg.name %>.js’: [’<%= concat.htmlhint.dest %>’]
- }
- }
- },
- relace: {
- htmlhint: {
- files: {‘lib/htmlhint.js’: ‘lib/htmlhint.js’},
- options: {
- prefix: ’@’,
- variables: {
- ‘VERSION’: ’<%= pkg.version %>’
- }
- }
- }
- }
- })
- grunt.registerTask(‘dev’, [‘jshint’, ‘concat’])
- grunt.registerTask(‘default’, [‘jshint’, ‘clean’, ‘concat’, ‘uglify’, ‘replace’])
- }