1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| module.exports = function (grunt) {
var sourceDir = "src";// 源码目录 var frontDir = "frontend";// 前端目录 var serverDir = "webapps";// 后端目录 var distDir = "dist";// 最终交付目录
// 从src拷贝到部署目录时,去掉中间的static路径 function clipStaticPath(dest, src){ var arr = src.split("/"); arr.splice(1, 1); var splicePath = arr.join("/"); return dest + "/" + splicePath; }
var thirdJSFiles = {};
thirdJSFiles[frontDir + "/3rd-lib/wechat-global.min.js"] = [ sourceDir + "/3rd-lib/*.js", sourceDir + "/resource/*.js" ];
var globalCSSFiles = {}; globalCSSFiles[frontDir + "/resource/css/wechat.min.css"] = [sourceDir + "/resource/css/*.css"];
grunt.initConfig({
uglify: { build: { options: { mangle: true }, files: [ { expand: true, flatten: false, cwd: sourceDir, src: ["**/static/**/*.js"], filter: "isFile", dest: frontDir, ext: ".min.js", rename: clipStaticPath } ] }, thirdjs: { options: { mangle: true }, files: thirdJSFiles } }, cssmin: { global: { files: globalCSSFiles }, build: { files: [ { expand: true, flatten: false, cwd: sourceDir, src: ["**/static/css/**/*.css"], dest: frontDir, ext: ".min.css", rename: clipStaticPath } ] } }, copy: { frontend: { files: [ { expand: true, flatten: false, cwd: sourceDir, src: ['resource/**/*.jpg', 'resource/**/*.png'], filter: 'isFile', dest: frontDir } ] }, server: { files: [ { expand: true, flatten: false, cwd: sourceDir, src: ['**/*', '!**/test/**/*', '!**/static/**/*', "!3rd-lib/**/*", "!resource/**/*"], filter: 'isFile', dest: serverDir } ] }, dist: { files: [ { expand: true, flatten: false, src: ['conf/**/*', frontDir + '/**/*', serverDir + '/**/*', 'package.json'], dest: distDir } ] } }, mkdir: { build: { options: { mode: 0777, create: [distDir + '/logs', distDir + '/public'] } } }, clean: { build: [frontDir, serverDir] } });
grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-mkdir'); grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['uglify', 'cssmin', 'copy', 'mkdir', 'clean']); };
|