Skip to content

Instantly share code, notes, and snippets.

@gwleuverink
Created November 9, 2018 08:55
Show Gist options
  • Save gwleuverink/096eba19f88b59655b3b3f832f01b926 to your computer and use it in GitHub Desktop.
Save gwleuverink/096eba19f88b59655b3b3f832f01b926 to your computer and use it in GitHub Desktop.
Laravel mix vendor.js + bundles setup
const mix = require('laravel-mix');
const fs = require('fs')
const resourcePath = 'resources/js/'
const assetPath = 'public/assets/'
/*
|--------------------------------------------------------------------------
| Helper functions
|--------------------------------------------------------------------------
*/
let scanDirectory = function (dir) {
// get all 'files' in this directory
return fs.readdirSync(dir).filter(file => {
return fs.statSync(`${dir}/${file}`).isFile();
});
};
/*
|--------------------------------------------------------------------------
| Mix vendor.js
|--------------------------------------------------------------------------
*/
mix.js(
resourcePath + 'vendor.js',
'public/assets/js'
)
/*
|--------------------------------------------------------------------------
| Mix all files in bundles directory
|--------------------------------------------------------------------------
*/
let bundlePath = assetPath + 'bundles/'
scanDirectory(bundlePath).forEach(filepath => {
mix.js(bundlePath + filepath, assetPath + 'bundles')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment