简体   繁体   English

Grunt的多个文件夹和文件

[英]Multiple folder and files with Grunt

I'm working with Grunt to minified JS. 我正在与Grunt合作来缩小JS。 I need to minified differents folder for different pages... for example workspace.min.js for the Workspace page, and dashboard.min.js for Dashboard page... 我需要缩小不同页面的differents文件夹...例如,工作区页面的workspace.min.js,仪表板页面的dashboard.min.js ...

How I need to configure my gruntfile? 我如何配置我的gruntfile? Can I add in my grunt file task for minified the CSS files too? 我也可以添加grunt文件任务来缩小CSS文件吗?

I put the actual code here for my gruntfile.js! 我把这里的实际代码放在我的gruntfile.js中! (I'm very new with Grunt... sorry) (我对Grunt很陌生...对不起)

Thanks!! 谢谢!!

module.exports = function (grunt) {

// Project configuration.
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    paths: {
        src: {
            js: ['Resources/js/workspace/*.js', 'Resources/plugins/redactor/*.js', 'Resources/plugins/jquery.cookie/jquery.cookie.js',
                '/Resources/plugins/holder/holder.js', '/Resources/plugins/jquery.numeric/jquery.numeric.min.js', '/Resources/plugins/smothZoom/jquery.smoothZoom.js',
            '/Resources/plugins/jquery-transit/jquery.transit.min.js','']
        },
        dest: {
            js: 'dist/workspace.js',
            jsMin: 'dist/workspace.min.js'
        }
    },
    concat: {
        js: {
            options: {
                separator: ';'
            },
            src: '<%= paths.src.js %>',
            dest: '<%= paths.dest.js %>'
        }
    },
    uglify: {
        options: {
            banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
            compress: true,
            mangle: true,
            sourceMap: true
        },
        build: {
            src: '<%= paths.src.js %>',
            dest: '<%= paths.dest.jsMin %>'
        }
    }
});

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');

// Default task(s).
grunt.registerTask('default', ['uglify']);

}; };

If you want to minify a number of files, you can create multiple keys like: 如果要缩小文件数量,可以创建多个键,例如:

    uglify: {
        scripts: {
            files:{
                '<%= dirs.dest%>/js/scripts.min.js': [
                    '<%= dirs.src%>/js/scripta.js',
                    '<%= dirs.src%>/js/scriptb.js',
                    '<%= dirs.src%>/js/scriptc.js'
                    ]
            }
        },
        someotherscript: {
            files:{
                '<%= dirs.dest %>/js/scriptd.min.js': '<%= dirs.src %>/js/scriptd.js'
            }
        }
    }

And then create a default task to run them all, like: 然后创建一个默认任务以全部运行它们,例如:

grunt.registerTask(
    'default',
    [
    'uglify:scripts',
    'uglify:someotherscript',
    ]
);

Then when you run grunt, it minifies them all. 然后,当您运行咕unt声时,它将全部缩小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM