Created
November 9, 2018 08:55
-
-
Save gwleuverink/096eba19f88b59655b3b3f832f01b926 to your computer and use it in GitHub Desktop.
Laravel mix vendor.js + bundles setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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