Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rawnato's avatar

Elixir Remove Folder

how do I remove a folder with elixir?

Tks.

0 likes
3 replies
petehouston's avatar
Level 2

You can extend elixir to add remove function.

var gulp = require('gulp');
var elixir = require('laravel-elixir');
var del = require('del'); // execute: $ npm install --save-dev 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' ]);
});

I already mentioned it in my blog, http://geek.petehouston.com/2015/02/14/extension-script-remove-files-folders-laravel-elixir/

7 likes
kocoten1992's avatar

@petehouston , my man, I'll push this further on google, so helpful :)

Note that the api have change, for now it is:

  var Elixir = require('laravel-elixir'); //https://laravel.com/docs/5.2/elixir#writing-elixir-extensions
  var del = require('del');

  var Task = Elixir.Task;

  Elixir.extend('del', function(path) {
  
      new Task('del', function() {
          console.log(`Current directory: ${process.cwd()}`); //for debug, remove this if you don't want
          return del(path);
      });
  });

You might want to checkout the option dryrun, I have a filename typo and keep wonder why that file not being delete https://www.npmjs.com/package/del#dryrun

Another option would be use https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback (fs will stop the script and scream out if file not exists :) ), a thumb up is, it default package of node so no need to npm install fs --save-dev

syed's avatar

With @petehouston's answer I was getting this error TypeError: this.queueTask is not a function

This helped 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' ]);
});

Found answer here: http://stackoverflow.com/a/32636266/1292050

3 likes

Please or to participate in this conversation.