我一直在尝试在Laravel项目中使用gulp创建一个构建系统,现在唯一的问题是在我的master.blade.php
文件中重命名正确的文件名。就像现在一样,它只跟随gulp-useref
参数中提供的文件名,但gulp-rev
修订的文件不会被gulp-rev-replace
替换。
这是我的gulp任务:
gulp.task('build', ['clean', 'scss', 'js', 'master'], function() {
var assets,
jsFilter = $.filter('**/*.js'),
cssFilter = $.filter('**/*.css');
return gulp.src('app/views/layouts/master.blade.php')
.pipe(assets = $.useref.assets({searchPath: '/'}))
.pipe(jsFilter)
.pipe($.uglify())
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe($.rename(function(path) {
if(path.extname === '.php') {
path.dirname = 'app/views/layouts';
} else {
path.dirname = 'public/assets';
}
}))
.pipe(gulp.dest('./'))
.pipe($.size({title: 'build files', showFiles: true}))
.on('end', function() {
setTimeout(function() {
// force watchify to close all watchers
process.exit();
});
});
});
默认master.blade.php
如下所示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{$title}}</title>
<!-- build:css assets/index.css -->
<!-- bower:css -->
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.css" />
<!-- endbower -->
<link rel="stylesheet" href="/.tmp/index.css">
<!-- endbuild -->
</head>
<body>
<section id="container">
<header>
@include('layouts.navbar')
</header>
<aside>
@include('layouts.sidebar')
</aside>
<section>
@yield('content')
</section>
<footer>
@include('layouts.footer')
</footer>
</section>
<!-- build:js assets/index.js -->
<!-- bower:js -->
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/lodash/dist/lodash.compat.js"></script>
<!-- endbower -->
<script src="/.tmp/index.js"></script>
<!-- endbuild -->
</body>
</html>
尽管 gulp-rev-replace
管道,结果仍然如此。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{$title}}</title>
<link rel="stylesheet" href="assets/index.css">
</head>
<body>
<section id="container">
<header>
@include('layouts.navbar')
</header>
<aside>
@include('layouts.sidebar')
</aside>
<section>
@yield('content')
</section>
<footer>
@include('layouts.footer')
</footer>
</section>
<script src="assets/index.js"></script>
</body>
</html>
答案 0 :(得分:5)
我发现了问题,gulp-rev-replace
文档提到他们默认只替换扩展名为['.js', '.css', '.html', '.hbs']
的文件。在replaceInExtensions
选项中传递[&#39; .php&#39;]。