Gruntfile.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. module.exports = function(grunt) {
  2. //初始化配置grunt任务
  3. grunt.initConfig({
  4. concat: {//任务名称
  5. curing: {
  6. src: ['global/js/cloud/curing.js','global/js/cloud/curingFN.js','global/js/cloud/curingHtml.js',
  7. 'global/js/cloud/page.js','global/js/tools.js','global/js/columnShow/columnShow.js',
  8. 'global/js/contacts/buildHtml.js'],
  9. dest: 'global/js/cloud/curing.concat.js'
  10. },
  11. build:{
  12. src: ['global/js/cloud/build.js','global/js/cloud/buildFN.js','global/js/cloud/buildHtml.js',
  13. 'global/js/cloud/page.js','global/js/tools.js','global/js/columnShow/columnShow.js',
  14. 'global/js/contacts/buildHtml.js'],
  15. dest: 'global/js/cloud/build.concat.js'
  16. },
  17. },
  18. pkg: grunt.file.readJSON('package.json'),
  19. uglify: {
  20. options: {
  21. banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'//添加banner
  22. },
  23. curing: {//任务一:压缩a.js,不混淆变量名,保留注释,添加banner和footer
  24. options: {
  25. mangle: true, //false 不混淆变量名
  26. preserveComments: 'false', //不删除注释,还可以为 false(删除全部注释),some(保留@preserve @license @cc_on等注释)
  27. footer:'\n/*! <%= pkg.name %> 最后修改于: <%= grunt.template.today("yyyy-mm-dd") %> */'//添加footer
  28. },
  29. files: {
  30. 'global/js/cloud/curing.min.js': ['global/js/cloud/curing.concat.js']
  31. }
  32. },
  33. build: {
  34. options: {
  35. mangle: true,
  36. preserveComments: 'false',
  37. footer:'\n/*! <%= pkg.name %> 最后修改于: <%= grunt.template.today("yyyy-mm-dd") %> */'
  38. },
  39. files: {
  40. 'global/js/cloud/build.min.js': ['global/js/cloud/build.concat.js']
  41. }
  42. },
  43. // build:{//任务二:压缩b.js,输出压缩信息
  44. // options: {
  45. // report: "min"//输出压缩率,可选的值有 false(不输出信息),gzip
  46. // },
  47. // files: {
  48. // 'output/js/b.min.js': ['js/main/b.js']
  49. // }
  50. // },
  51. // buildall: {//任务三:按原文件结构压缩js文件夹内所有JS文件
  52. // files: [{
  53. // expand:true,
  54. // cwd:'js',//js目录下
  55. // src:'**/*.js',//所有js文件
  56. // dest: 'output/js'//输出到此目录下
  57. // }]
  58. // },
  59. // release: {//任务四:合并压缩a.js和b.js
  60. // files: {
  61. // 'output/js/index.min.js': ['js/a.js', 'js/main/b.js']
  62. // }
  63. // }
  64. },
  65. jshint:{
  66. options:{
  67. jshintrc:'.jshintrc'
  68. },
  69. build:['global/js/cloud/*.min.js']
  70. },
  71. // watch: {
  72. // scripts: {
  73. // files: ['**/*.js'],
  74. // tasks: ['concat','uglify','jshint'],
  75. // options: {
  76. // spawn: false,
  77. // },
  78. // },
  79. // },
  80. });
  81. grunt.loadNpmTasks('grunt-contrib-concat');
  82. grunt.loadNpmTasks('grunt-contrib-uglify');
  83. grunt.loadNpmTasks('grunt-contrib-jshint');
  84. grunt.loadNpmTasks('grunt-contrib-watch');
  85. //注册grunt默认任务
  86. grunt.registerTask('default', ['concat','uglify','jshint']);
  87. //grunt.registerTask('default', ['concat','uglify','jshint','watch']);
  88. };