GruntJS配置还是比较耗时间的,这里放出一份我在h萌的一个项目的GruntJS的编译配置。这个编译配置参考了网络上的许多地方的配置文件整合的
JSON文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | { "name": "", "version": "0.1.0", "dependencies": { "grunt": "0.x.x", "grunt-autoprefixer": "0.2.x", "grunt-contrib-clean": "0.5.x", "grunt-contrib-coffee": "0.7.x", "grunt-contrib-connect": "0.4.x", "grunt-contrib-copy": "0.4.x", "grunt-contrib-cssmin": "0.6.x", "grunt-contrib-jade": "0.8.x", "grunt-contrib-jshint": "0.6.x", "grunt-contrib-stylus": "0.8.x", "grunt-contrib-uglify": "0.2.x", "grunt-contrib-watch": "0.5.x", "grunt-html-build":"0.3.x", "grunt-contrib-htmlmin":"0.3.x", "grunt-cleanempty":"1.0.x" }, "engine": "node >= 0.10" } |
下面是关键的JS
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | module.exports = function(grunt) { // configure the tasks grunt.initConfig({ copy: { build: { cwd: 'static', src: [ '**', '!**/*.styl', '!**/*.coffee', '!**/*.jade' ,'!**.bak','!**.log','!**.html'], dest: 'build', expand: true }, }, clean: { build: { src: [ 'build' ] }, stylesheets: { src: [ 'build/**/*.css', '!build/application.css' ] }, scripts: { src: [ 'build/**/*.js', '!build/application.js' ] }, }, stylus: { build: { options: { linenos: true, compress: false }, files: [{ expand: true, cwd: 'static', src: [ '**/*.styl' ], dest: 'build', ext: '.css' }] } }, autoprefixer: { build: { expand: true, cwd: 'build', src: [ '**/*.css' ], dest: 'build' } }, cssmin: { build: { files: { 'build/application.css': [ 'build/**/*.css' ] } } }, coffee: { build: { expand: true, cwd: 'static', src: [ '**/*.coffee' ], dest: 'build', ext: '.js' } }, uglify: { build: { options: { mangle: false }, files: { 'build/application.js': [ 'build/**/*.js' ] } } }, jade: { compile: { options: { data: {} }, files: [{ expand: true, cwd: 'static', src: [ '**/*.jade' ], dest: 'build', ext: '.html' }] } }, fixturesPath: "path", htmlbuild: { dist: { src: ['static/*.html'], dest: 'build/', options: { beautify: false, prefix: '//some-cdn', relative: true, scripts: { }, styles: { }, sections: { }, data: { }, } } }, htmlmin: { // Task multiple: { options: { // Target options removeComments: true, collapseWhitespace: true }, // Target files: [{ // Dictionary of files expand: true, cwd: 'build/', // Project root src: '**/*.html', // Source dest: 'build/' // Destination }] } }, cleanempty: { options: { force: true, }, src: ['build/**/*', 'build/*'], }, }); // load the tasks grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-autoprefixer'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-coffee'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-jade'); grunt.loadNpmTasks('grunt-contrib-stylus'); grunt.loadNpmTasks('grunt-html-build'); grunt.loadNpmTasks('grunt-contrib-htmlmin'); grunt.loadNpmTasks('grunt-cleanempty'); // define the tasks grunt.registerTask( 'stylesheets', 'Compiles the stylesheets.', [ 'stylus', 'autoprefixer', 'cssmin', 'clean:stylesheets' ] ); grunt.registerTask( 'scripts', 'Compiles the JavaScript files.', [ 'coffee', 'uglify', 'clean:scripts' ] ); grunt.registerTask( 'build', 'Compiles all of the assets and copies the files to the build directory.', [ 'clean:build', 'copy', 'stylesheets', 'scripts', 'jade','htmlbuild' ,'htmlmin','cleanempty'] ); grunt.registerTask( 'default', '', [ 'build'] ); }; |