Support the ongoing development of Laravel.io →
Configuration Packages Architecture

I have a folder inside my "assets" that contains multiple javascripts files. I have many folders in my assets, one for each purpose and all managed by Laravel Elixir with Gulp:

/assets
    /css
        /general
            style.css
            themes.css
        /styles
            products.css
            single_item.css
            customer.css
    /js
        /general
            core.js
            site.js
        /scripts
            products.js
            single_item.js
            customer.js

I already use "scripts" and "styles" plugin with Elixir in order to minify and combine all JS scripts from assets/js/general and all CSS files from assets/css/general into one single file inside /public/www/js/script.js and /public/www/css/style.css respectively.

Now what I need is having Elixir to minify every single file individually inside assets/js/scripts and to put them all inside /public/www/js/scripts without combining them into one single file. I also need the same for CSSs inside assets/css/styles.

I could use "scripts" and "styles" specifying every single file manually, like that:

Elixir(function (mix) {
	mix

	.scripts([
		'assets/js/scripts/products.js'
	], 'public/manager/js/scripts/products.js')

	.scripts([
		'assets/js/scripts/single_item.js'
	], 'public/manager/js/scripts/single_item.js')
	
	/* ... and so on .... */
});

But let's say it would be frustrating...

I found a nice Gulp task here: https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-task-steps-per-folder.md It does the trick, even though it handles directories instead of files: it creates a minified version of all files contained in each directory, the result is as many minified files as the number of directories. I could put every file inside a directory. Anyway I wasn't able to create a new Elixir plugin inside /node_modules/laravel-elixir/tasks that integrates that task (I'm very new to Elixir). I tried to paste that script inside my gulpfile.js after the Elixir definitions, but I found these problems (I renamed the task name to "scriptsfolder"):

  • Running gulp.task('default', ['scriptsfolder']); ignores Elixir tasks;
  • Running gulp.task('scriptsfolder'); runs Elixir tasks but not scriptsfolder;
  • That script is not exactly what I need: I need all files in one directory to be minified individually and not combined, not all files inside each directory...

I really can't figure out how to integrate this behaviour.

Is there a way to integrate that script (or a better version that handles files instead of directories) into Elixir? Or is there a way to achieve my desired behaviour with Elixir? Of course I also need to be able to watch that process as well as I'm already doing with the other Elixir tasks.

Thank you.

Last updated 3 years ago.
0

Have you find a solution to your problem ? I'm exaclty in the same situation. Help welcome...

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

tobispace tobispace Joined 31 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.