- 在laravel项目根目录下,创建一个ant.php,将下面的内容复制进去:
<?php
/**
* 说明:获取文件
*
* @param $dir
* @return array
* @author scort
*/
function getFile($dir) {
$handler = opendir($dir);
while (($filename = readdir($handler)) !== false) {//务必使用!==,防止目录下出现类似文件名“0”等情况
if ($filename != "." && $filename != "..") {
$files[] = $filename ;
}
}
closedir($handler);
return $files;
}
//获取某目录下所有文件、目录名(不包括子目录下文件、目录名)
$cssFiles = getFile('./resources/assets/css/');
$jsFiles = getFile('./resources/assets/js/');
$info = "var elixir = require('laravel-elixir');\n";
$info .=<<<EOF
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Sass
| file for our application, as well as publishing vendor resources.
|
*/
EOF;
$info .= "elixir(function(mix) {\n";
//打印所有文件名
foreach ($cssFiles as $value) {
$info .= "\tmix.styles('{$value}', 'public/build/css');\n";
}
foreach ($jsFiles as $value) {
$info .= "\tmix.scripts('{$value}', 'public/build/js');\n";
}
$info .= '});';
file_put_contents('gulpfile.js', $info);
system('gulp --production');