grunt构建

来源:互联网 发布:海岛奇兵极冻先锋数据 编辑:程序博客网 时间:2024/06/08 03:59

package.json

{  "name": "zhangton",  "version": "1.0.0",  "description": "",  "main": "index.js",  "directories": {    "test": "test"  },  "scripts": {    "test": "grunt test"  },  "author": "",  "license": "ISC",  "dependencies": {    "grunt": "^0.4.5",    "grunt-contrib-clean": "latest",    "grunt-contrib-cssmin": "latest",    "grunt-contrib-jshint": "latest",    "grunt-contrib-uglify": "latest",    "grunt-contrib-less": "latest",    "grunt-contrib-copy": "latest",    "grunt-ssh": "latest"  }}

gruntfile.js

var uploadFiles = [    'images/**',    'dist/style/**',    'dist/js/**',    'dist/html/**',    '*.html'];module.exports = function (grunt) {    grunt.initConfig({        pkg: grunt.file.readJSON('package.json'),        clean: {            all: ['dist']        },        uglify: {//压缩js            my_target: {                options: {                    sourceMap: false                },                files: [{                    expand: true,                    cwd: 'js',                    src: '*.js',                    dest: 'dist/js',                    ext: '.min.js'                }]            }        },        cssmin: {//压缩css            build: {                expand: true,                cwd: 'style',                src: ['*.css'],                dest: 'dist/style',                ext: '.min.css'            }        },        less: {//less            main: {                expand: true,                src: ['style/*.less'],                dest: 'dist',                ext: '.css'            }        },        copy: {            html: {                files: [{                    expand: true,                    cwd: 'html',                    src: ['*.html'],                    dest: 'dist/html'                }]            }        },        secret: grunt.file.readJSON('secret.json'),        sftp: {            test: {                files: {                    "./": uploadFiles                },                options: {                    path: '<%= secret.test.path %><%= pkg.name %>',                    host: '<%= secret.test.host %>',                    username: '<%= secret.test.username %>',                    password: '<%= secret.test.password %>',                    showProgress: true,                    createDirectories: true                }            },            product: {                files: {                    "./": uploadFiles                },                options: {                    path: '<%= secret.product.path %><%= pkg.name %>',                    host: '<%= secret.product.host %>',                    username: '<%= secret.product.username %>',                    password: '<%= secret.product.password %>',                    showProgress: true,                    createDirectories: true                }            }        }    });    grunt.loadNpmTasks('grunt-contrib-clean');    grunt.loadNpmTasks('grunt-contrib-uglify');    grunt.loadNpmTasks('grunt-contrib-cssmin');    grunt.loadNpmTasks('grunt-contrib-less');    grunt.loadNpmTasks('grunt-contrib-copy');    grunt.loadNpmTasks('grunt-ssh');    //grunt.registerTask('test', ['clean', 'uglify', 'cssmin','less','copy', 'sftp:test']);    //grunt.registerTask('product', ['clean', 'uglify', 'cssmin','less','copy', 'sftp:product']);};
0 0