Delete intermediary files after elixir merge

2019-04-10 23:12发布

问题:

I am using Laravel 5. During gulp task, the processed SASS files and other CSS files copied from resource folder are stored in public/css. Then all the files in the public/css are merged together to a single file as "all.css". So the files that were created needs to be deleted.

How can I do this?

回答1:

For newer versions of laravel this worked for me:

var elixir = require('laravel-elixir');
var del = require('del');

elixir.extend('remove', function(path) {
    new elixir.Task('remove', function() {
        del(path);
    });
});

elixir(function(mix) {
    mix.remove([ 'public/css', 'public/js' ]);
});

Cheers!



回答2:

It was well explained here , anyway just in case it is a broken link, this is what I do and works perfectly. Basically you have to extend gulp and add a "remove" function which uses "del", your last task is just removing the intermediate files once the versioning is finished.

var gulp = require('gulp');
var elixir = require('laravel-elixir');
var del = require('del');

elixir.extend("remove", function(path) {
    gulp.task("remove", function() {
        del(path);
    });
    return this.queueTask("remove");
});

// Usage
elixir(function(mix) {
    mix.remove([ 'public/css', 'public/js' ]);
});

You will probably need to install some npm pagackes like so:

$ npm install --save-dev del
$ npm install --save-dev wrappy
$ npm install --save-dev brace-expansion