Gruntfile.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. module.exports = function(grunt) {
  2. 'use strict';
  3. grunt.initConfig({
  4. pkg: grunt.file.readJSON('package.json'),
  5. build: {
  6. options: {
  7. banner: '/*! WebUploader <%= pkg.version %> */\n'
  8. },
  9. all: {
  10. name: 'webuploader',
  11. dest: "dist/webuploader.js",
  12. // 在没有jquery类似的库的前提下可以设置builtin,去除强行依赖。
  13. builtin: {
  14. dollar: false,
  15. promise: false
  16. }
  17. },
  18. nolog: {
  19. preset: 'all',
  20. dest: "dist/webuploader.nolog.js",
  21. // 在没有jquery类似的库的前提下可以设置builtin,去除强行依赖。
  22. builtin: {
  23. dollar: false,
  24. promise: false
  25. }
  26. },
  27. flashonly: {
  28. preset: 'flashonly',
  29. dest: "dist/webuploader.flashonly.js",
  30. },
  31. html5only: {
  32. preset: 'html5only',
  33. dest: "dist/webuploader.html5only.js",
  34. },
  35. withoutimage: {
  36. preset: 'withoutimage',
  37. dest: "dist/webuploader.noimage.js",
  38. },
  39. // 自己配置的实例
  40. // glob语法。
  41. // 移动端方案,请搭配 zepto 使用。
  42. custom: {
  43. preset: "custom",
  44. cwd: "src",
  45. builtin: {
  46. promise: true
  47. },
  48. src: [
  49. 'widgets/filepicker.js',
  50. 'widgets/image.js',
  51. 'widgets/queue.js',
  52. 'widgets/runtime.js',
  53. 'widgets/upload.js',
  54. 'widgets/log.js',
  55. 'runtime/html5/blob.js',
  56. 'runtime/html5/filepicker.js',
  57. 'runtime/html5/imagemeta/exif.js',
  58. 'runtime/html5/image.js',
  59. 'runtime/html5/androidpatch.js',
  60. 'runtime/html5/transport.js'
  61. ],
  62. dest: "dist/webuploader.custom.js"
  63. },
  64. fis: {
  65. name: 'webuploader',
  66. dest: "dist/webuploader.fis.js",
  67. fis: true,
  68. // 在没有jquery类似的库的前提下可以设置builtin,去除强行依赖。
  69. builtin: {
  70. dollar: false,
  71. promise: false
  72. }
  73. }
  74. },
  75. uglify: {
  76. options: {
  77. mangle: true,
  78. banner: '/* WebUploader <%= pkg.version %> */'
  79. },
  80. static_mapping: {
  81. files: [
  82. {
  83. src: 'dist/webuploader.js',
  84. dest: 'dist/webuploader.min.js'
  85. },
  86. {
  87. src: 'dist/webuploader.nolog.js',
  88. dest: 'dist/webuploader.nolog.min.js'
  89. },
  90. {
  91. src: 'dist/webuploader.flashonly.js',
  92. dest: 'dist/webuploader.flashonly.min.js'
  93. },
  94. {
  95. src: 'dist/webuploader.html5only.js',
  96. dest: 'dist/webuploader.html5only.min.js'
  97. },
  98. {
  99. src: 'dist/webuploader.noimage.js',
  100. dest: 'dist/webuploader.noimage.min.js'
  101. },
  102. {
  103. src: 'dist/webuploader.custom.js',
  104. dest: 'dist/webuploader.custom.min.js'
  105. }
  106. ]
  107. }
  108. },
  109. copy: {
  110. jekyll: {
  111. src: 'dist/webuploader.js',
  112. dest: 'jekyll/js/webuploader.js',
  113. },
  114. css: {
  115. src: 'css/webuploader.css',
  116. dest: 'dist/webuploader.css'
  117. },
  118. css2: {
  119. src: 'css/webuploader.css',
  120. dest: 'jekyll/css/webuploader.css'
  121. }
  122. },
  123. watch: {
  124. options: {
  125. debounceDelay: 250
  126. },
  127. all: {
  128. files: ['src/**/*.js', 'Gruntfile.js'],
  129. tasks: ['default'],
  130. },
  131. dist: {
  132. files: ['src/**/*.js', 'Gruntfile.js'],
  133. tasks: ['dist'],
  134. },
  135. doc: {
  136. files: ['src/**/*.js', 'Gruntfile.js', 'build/docTpl/**/*'],
  137. tasks: ['doc'],
  138. },
  139. dev: {
  140. files: 'src/**/*.js',
  141. tasks: 'build:all'
  142. },
  143. flashonly: {
  144. files: 'src/**/*.js',
  145. tasks: 'build:flashonly'
  146. }
  147. },
  148. jsbint: {
  149. options: {
  150. jshintrc: '.jshintrc'
  151. },
  152. all: [
  153. 'src/**/*.js',
  154. '!src/runtime/html5/jpegencoder.js'
  155. ]
  156. },
  157. size: {
  158. dist: {
  159. cwd: 'dist/',
  160. src: '*.js'
  161. },
  162. src: {
  163. src: 'src/**/*.js'
  164. }
  165. },
  166. doc: {
  167. options: {
  168. cwd: './src/',
  169. files: [
  170. 'uploader.js',
  171. 'base.js',
  172. 'mediator.js',
  173. '**/*.js'
  174. ],
  175. tplDir: './build/docTpl',
  176. theme: 'gmu',
  177. outputDir: './jekyll/doc',
  178. title: 'WebUploader API文档'
  179. }
  180. },
  181. jekyll: {
  182. options: { // Universal options
  183. src: 'jekyll'
  184. },
  185. dist: { // Target
  186. options: { // Target options
  187. dest: 'pages',
  188. config: 'jekyll/_config.yml'
  189. }
  190. }
  191. },
  192. 'gh-pages': {
  193. options: {
  194. message: '程序自动提交,源码请查看tree/master/jekyll目录',
  195. base: 'pages',
  196. repo: 'https://github.com/fex-team/webuploader.git'
  197. },
  198. src: ['**/*']
  199. },
  200. qunit: {
  201. all: {
  202. options: {
  203. urls: [
  204. 'http://0.0.0.0:8000/test/index.html'
  205. ]
  206. }
  207. }
  208. },
  209. connect: {
  210. server: {
  211. options: {
  212. port: 8000,
  213. base: '.'
  214. }
  215. }
  216. /*,
  217. keepalive: {
  218. options: {
  219. port: 8000,
  220. base: '.',
  221. keepalive: true
  222. }
  223. }*/
  224. },
  225. });
  226. require('load-grunt-tasks')(grunt);
  227. grunt.loadTasks('build/tasks'); // 加载build目录下的所有task
  228. // Default task(s).
  229. grunt.registerTask('default', ['jsbint:all', 'dist']);
  230. grunt.registerTask('dist', ['build', 'uglify', 'copy']);
  231. grunt.registerTask('deploy', ['doc', 'jekyll', 'gh-pages']);
  232. grunt.registerTask('test', ['connect', 'qunit']);
  233. };