使用Grunt Uglify JS文件

时间:2017-10-27 11:27:03

标签: javascript angular gruntjs uglifyjs grunt-contrib-uglify

我正在使用Grunt来uglify所有的JS文件。

但我的问题是有什么办法,可以跳过某些特殊条件下的js文件。

例如,我有2个用于测试的临时环境。我不希望我的js文件对于这两个临时环境是uglify。对于生产,js文件应该是uglify。

有没有办法实现这一点通过使用Grunt?我试着寻找解决方案。但没有运气。

clean: {
        build:[
            "target"
        ],
        postbuild:['target/js/<%= pkg.name %>.js', 'target/js/lib', 'target/src/js']
    },

    concat: {
        options: {
            separator: ';'
        },
        target: {
            src: ['src/js/app/**/*.js'],
            dest: 'target/js/<%= pkg.name %>.js'
        }
    },

    jshint: {
        files: ['Gruntfile.js', 'src/js/app/**/*.js', 'test/unit/**/*.js'],
        options: {
            // options here to override JSHint defaults
            globals: {
                jQuery: true,
                console: true,
                module: true,
                document: true
            }
        }
    },
    useref: {
        // specify which files contain the build blocks
        html: 'target/*.html',
        // explicitly specify the temp directory you are working in
        // this is the the base of your links ( '/' )
        temp: 'target'
    },

    copy: {
        main:{
            files: [
                {expand: true, cwd: 'css/', src: ['**/*.*'], dest: 'target/css'},
                {expand: true, cwd: 'css/fonts', src: ['**/*.*'], dest: 'target/css/fonts'},

                {expand: true, flatten: true, cwd: 'images/', src: ['**'], dest: 'target/images'},

                {expand: true, cwd: 'js/lib', src: ['**/*.js'], dest: 'target/js/lib'},
                {expand: true, cwd: 'src/js/app', src: ['**/*.js'], dest: 'target/src/js/app'},

                {expand: true, cwd: 'templates', src: ['**/*.*'], dest: 'target/templates'},                
                {expand: true, cwd: '', src: ['index.html', 'appindex.html'], dest: 'target'},
                {expand: true, cwd: 'properties', src: ['**/*','!**/eenavigation/**'], dest: 'target/properties'}
            ],

            options: {
                files: ['package.json'], // list of files to add build info
                buildField: 'buildInfo' // add a 'buildInfo' element to the package.json containing the build info
            }
        },

        postBuildTraining: {
            files:[

            //  copy training folder for training environment alone
                {expand: true, cwd: 'training', src: ['**/*.*'], dest: 'target/training'},
                {expand: true, cwd: 'traininghtml', src: ['**/*.*'], dest: 'target/traininghtml'}
            ]
        },
        postBuild: {
            files:[

                //  Copy IE specific files. These are already minified
                {expand: true, cwd: 'js/lib', src: ['html5shiv.min.js', 'respond.min.js'], dest: 'target/js/lib'},

                //  jQuery is imported within the Thistle redirect HTML, so we need to provide a copy for successful import
                {expand: true, cwd: 'js/lib/jquery', src: ['jquery-1.*.js'], dest: 'target/js/lib/jquery'},

                //  Copy the lib.js JavaScript file so that it is accessible from the redirect files
                {expand: true, cwd: 'js/lib', src: ['lib.js'], dest: 'target/js/lib/'}

            ]
        }
   },

    uglify: {
        options: {
            // the banner is inserted at the top of the output
            banner: '/*! <%= grunt.template.today("dd-mm-yyyy HH:MM:ss") %> */\n'
        }
    },

0 个答案:

没有答案