grunt-contrib-uglify和npm install

时间:2016-11-23 13:52:10

标签: javascript node.js grunt-contrib-uglify

我创建了一个小grunt文件,使我的编码更容易 - 如果有人想在自己的项目中使用它,我粘贴下面的代码:) - 但我有一个关于添加新脚本的问题...

在许多情况下,您可以通过npm install安装脚本/框架/或任何您想要的内容(例如swiper或chart.js)。它简单,容易和快速,但那又如何呢?如何将该脚本添加到grunt-uglify?我总是从dist文件夹中复制编译后的脚本并将其粘贴到/ assets / src / js ...然后运行uglify。但我认为有更快的方法可以解决项目中使用的所有脚本,也许有人知道吗?

问候,W

/*
 * Copyright (c) 2016.  Wojciech.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

'use strict';

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        //CSS
        compass: {
            dev: {
                options: {
                    sassDir: 'assets/src/sass',
                    cssDir: 'assets/css-dev',
                    environment: 'development',
                    outputStyle: 'expanded'
                }
            },

            prod: {
                options: {
                    sassDir: 'assets/src/sass',
                    cssDir: 'assets/css',
                    environment: 'production',
                    outputStyle: 'compressed'
                }
            }
        },
        //JS
        jshint: {
            all: ['assets/src/js/jquery.scripts.js', 'assets/src/js/angular/**/*.js', 'assets/src/js/functions/**/*.js']
        },
        ngAnnotate: {
            options: {
                singleQuotes: true
            },
            app: {
                files: {
                    'assets/src/js/angular/min-safe/ngApp.js': ['assets/src/js/angular/npApp.js', 'assets/src/js/angular/controllers/*.js']
                }
            }
        },
        concat: {
            options: {
              separator: ';'
            },
            dist: {
              src: ['assets/src/js/angular/min-safe/ngApp.js',  'assets/src/js/pluginsfirst/*.js', 'assets/src/js/plugins/*.js', 'assets/src/js/functions/*.js','assets/src/js/jquery.scripts.js'],
              dest: 'assets/js/main.js'
            }
        },
        uglify: {
            options: {
                banner: '/* <%= pkg.name %> - v <%= pkg.version %> - ' +
                        '<%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            my_advanced_target: {
                files: {
                    'assets/js/main.min.js': ['assets/js/angular.js', 'assets/js/main.js']
                }
            }
        },
        watch: {
            options: {
              dateFormat: function(time) {
                grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString());
                grunt.log.writeln('Waiting for more changes...');
              }
            },
            def: {
                files: ['assets/src/js/**/*.js', 'assets/src/sass/**/*.scss'],
                tasks: ['jshint', 'ngAnnotate', 'concat', 'uglify', 'compass:dev']
            },
            js: {
                files: 'assets/src/js/**/*.js',
                tasks: ['jshint', 'ngAnnotate', 'concat', 'uglify']
            },
            compass_dev: {
                files: 'assets/src/sass/**/*.scss',
                tasks: ['compass:dev']
            },
            compass: {
                files: 'assets/src/sass/**/*.scss',
                tasks: ['compass:prod']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-ng-annotate');

    grunt.registerTask('default', ['watch:def']);
    grunt.registerTask('watch-js', ['watch:js']);
    grunt.registerTask('watch-compass-dev', ['watch:compass_dev']);
    grunt.registerTask('watch-compass', ['watch:compass']);
};

0 个答案:

没有答案