gulp with object files key as dest和array as source

时间:2014-07-27 14:36:03

标签: gruntjs gulp

我有这个json文件

{
   "vendor":{ 
        "css": {
            "public/build/css/vendor.min.css": [
                "public/bower_components/bootstrap/dist/css/bootstrap.min.css"
             ]
        },
        "js": {
            "public/build/js/vendor.min.js": [
                "public/bower_components/lodash/dist/lodash.min.js",
                "public/bower_components/jquery/dist/jquery.min.js",
                "public/bower_components/bootstrap/dist/js/bootstrap.min.js",
                "public/bower_components/angular/angular.min.js",
                "public/bower_components/angular-ui-router/release/angular-ui-router.min.js",
                "public/bower_components/restangular/dist/restangular.min.js"
            ]
        }
    },
    "scripts":{ 
       "css": {
            "public/build/css/scripts.min.css": [
                "public/*/assets/css/*.css"
            ]
       },
       "js": {
            "public/build/js/scripts.min.js": [
                "public/init.js",
                "public/system/system.js",
                "public/system/controllers/*.js",
                "public/system/directives/*.js",
                "public/system/filters/*.js",
                "public/system/routes/*.js",
                "public/system/services/*.js",
                "public/users/users.js",
                "public/users/controllers/*.js",
                "public/users/directives/*.js",
                "public/users/routes/*.js",
                "public/users/services/*.js"
            ]
        }
    }
}

我的咕噜文件

'use strict';



var paths = {
    js: ['Gruntfile.js', 'tasks/laravel.js', 'public/**/*.js', '!public/build/**', '!public/bower_components/**'],
    html: ['public/**/views/**'],
    css: ['public/**/assets/css/*.css', '!public/bower_components/**'],
    php: ['app/**/*.php', '!vendor/**']
};

module.exports = function(grunt) {

    require('time-grunt')(grunt);

   // Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        assets: grunt.file.readJSON('app/config/assets.json'),
        clean: ['public/build'],
        watch: {
            css: {
                files: paths.css,
                tasks: ['csslint'],
                options: {
                    livereload: true
                }
            },
            html: {
                files: paths.html,
                options: {
                    livereload: true
                }
            },
            js: {
                files: paths.js,
                tasks: ['jshint'],
                options: {
                    livereload: true
                }
            },
            php: {
                files: paths.php,
                options: {
                    livereload: true
                }
            }
        },
        jshint: {
            all: {
                src: paths.js,
                options: {
                    jshintrc: true
                }
            }
        },
        csslint: {
            options: {
                csslintrc: '.csslintrc'
            },
            src: paths.css
        },
        laravel:{
           dist:{}
        },
        concurrent: {
            tasks: ['laravel', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        },
        concat:{
            productionCssVendor:{
                files: '<%= assets.vendor.css %>',
                nonull: true
            },
            productionJsVendor:{
                files: '<%= assets.vendor.js %>',
                nonull: true
            }
        },
        cssmin: {
            productionScripts: {
                files: '<%= assets.scripts.css %>'
            }
        },
        uglify: {
            options: {
                mangle: false
            },
            productionScripts: {
                files: '<%= assets.scripts.js %>'
            }
        }
    });

    grunt.loadTasks('tasks');  
    require('load-grunt-tasks')(grunt);

    grunt.registerTask('default', ['jshint','concurrent']);
    grunt.registerTask('prod', ['clean', 'concat', 'cssmin','uglify']);

};

如何使用gulp获得相同的东西,例如concat和uglify?

比这更好:(

var fs = require('fs');
var assets = JSON.parse(fs.readFileSync('app/config/assets.json', 'utf8'));
var jsVendor = Object.keys(assets.vendor.js);
var srcJsVendor = assets.vendor.js[jsVendor[0]];
var chunks = jsVendor[0].split('/');
var concatFilename = chunks.pop();

gulp.task('concat', function() {
  return gulp.src(srcJsVendor)
    .pipe(concat(concatFilename))
    .pipe(gulp.dest(chunks.join('/')+'/'))
    .pipe(notify({ message: 'Scripts task complete' }));
});

0 个答案:

没有答案