简体   繁体   English

创建多个grunt任务

[英]Create multiple grunt task

watch: {
    css: {
        files: 'source/styles/**/*.scss',
        tasks: ['sass', 'autoprefixer', 'cssmin', 'clean:css'],
        options: {
            spawn: false,
        },
    },
    images: {
        files: 'source/assets/images/**/*.{png,jpg,gif}',
        tasks: ['clean:image', 'imagemin'],
        options: {
            spawn: false,
        },
    }
}



grunt.registerTask('css', [
    'sass',
    'cssmin',
    'clean:css'
]);



sass: {
    dist: {
        files: [{
            expand: true,
            src: ['source/styles/**/*.scss'],
            dest: 'build/styles/',
            ext: '.css',
            flatten: true
        }]
    },
    options: {
        compass: true,
        sourcemap: false
    }
}


grunt.registerTask('default', [
    'sass',
    'cssmin',
    'clean:css',
    'requirejs',
    'clean:js',
]);

I want to create a new gurnt task. 我想创建一个新的任务。 Currenly, In my project, grunt css is working fine to build the complate packae SCSS. Currenly,在我的项目中,咕unt的grunt css可以很好地构建comppack packSCSS。 I need to create a new task like grunt home , which will build a specific folder SCSS. 我需要创建一个新任务,例如grunt home ,它将建立一个特定的文件夹SCSS。

How can I create grunt home ? 如何创建grunt home

I think this should work, but i didn't test it (it will compile SCSS files from source/styles/SCSS to css in build/styles/css): 我认为这应该可行,但是我没有对其进行测试(它将将SCSS文件从源代码/样式/ SCSS编译为build / styles / css中的css):

homeSass: {
    dist: {
        files: [{
            expand: true,
            src: ['source/styles/SCSS/**/*.scss'],
            dest: 'build/styles/css/',
            ext: '.css',
            flatten: true
        }]
    },
    options: {
        compass: true,
        sourcemap: false
    }
}

grunt.registerTask('homebuild', [
    'homeSass'
]);

Is it your are looking for? 是您要找的吗? Or I misunderstand you? 还是我误会你了?

so something like this you can create multiple tasks 所以像这样你可以创建多个任务

sass2: {
    dist: {
        files: [{
            expand: true,
            src: ['source/styles/**/*.scss'],//path to different source file
            dest: 'build/styles/',//path to different destination for home
            ext: '.css',
            flatten: true
        }]
    },
    options: {
        compass: true,
        sourcemap: false
    }
}

grunt.registerTask('home', [
    'sass2'
]);

Now to run this you have 2 ways 现在运行此方法有两种方法

1) simply say grunt home this will only run sass compilation specific to sass2 1)简单地说grunt home这只会运行特定于sass2的sass编译

2) now if you wants to run both the tasks grunt css and grunt home in 1 go then do this 2)现在,如果您想同时运行grunt cssgrunt home这两个任务,请执行此操作

sass: {
    dist: {
        files: [{
            expand: true,
            src: ['source/styles/**/src1.scss', 'source/styles/**/src2.scss'],
            dest: 'build/styles/',
            ext: '.css',
            flatten: true
        }]
    },
    options: {
        compass: true,
        sourcemap: false
    }
}

grunt.registerTask('home', [
    'sass'
]);

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

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