我是靠谱客的博主 精明手机,这篇文章主要介绍grunt安装使用简介,现在分享给大家,希望可以做个参考。

grunt是一个基于任务的实现自动化工作流的平台

安装

  1. npm uninstall grunt -g //卸载grunt
  2. npm install grunt-cli -g //安装grunt-cli
  3. npm install grunt-init -g //安装grunt-init 自动初始化grunt工程 可选安装

grunt-init是个脚手架工具,它可以帮你完成项目的自动化创建,包括项目的目录结构,每个目录里的文件等。具体情况要看你运行grunt-init指定的模板,以及创建过程中你对问题的回答。

配置

从官网下载package.json,gruntfile.js文件放到项目的根目录,并对它们进行修改配置

  • package.json //项目自动化所依赖的相关插件
  • gruntfile.js //项目自动化工作流配置文件 重要
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
//package.json: { "name":"my-project-name", "version": "0.1.0", "devDependencies":{ "grunt":"~0.4.1", "grunt-contrib-jshint":"~0.6.0", "grunt-contrib-nodeunit": "~0.2.2", "grunt-contrib-uglify": "~0.2.2" } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//gruntfile.js: commonJs模块定义方式 module.export = function(grunt){ //project configuration grunt.initConfig(function(){ pkg: grunt.file.readJSON('package.json'), uglify: { options:{ banner:'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") */' }, build:{ src: "src/<%= pkg.name %>.js", dest: "build/<%= pkg.name %>.min.js" } } }); } //load the plugin that provides the "unglify" task grunt.loadNpmTasks('grunt-contrib-uglify'); //default task(s) grunt.registerTask('default',['uglify']);

转载于:https://www.cnblogs.com/stephenykk/p/4171781.html

最后

以上就是精明手机最近收集整理的关于grunt安装使用简介的全部内容,更多相关grunt安装使用简介内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部