gulp-rev-replace 没有更改我 master.blade.php 中的修订文件名
gulp-rev-replace isn't changing the revisioned file names in my master.blade.php
我一直在尝试在 Laravel 项目中使用 gulp 创建一个构建系统,现在唯一剩下的问题是在我的 master.blade.php
文件中重命名正确的文件名.就像现在一样,它仅遵循 gulp-useref
parameters, but the files revisioned by gulp-rev
are not replaced by 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>
我发现了问题,gulp-rev-replace
文档提到他们默认只替换扩展名为 ['.js', '.css', '.html', '.hbs']
的文件。通过在 replaceInExtensions
选项中传递 ['.php']。
我一直在尝试在 Laravel 项目中使用 gulp 创建一个构建系统,现在唯一剩下的问题是在我的 master.blade.php
文件中重命名正确的文件名.就像现在一样,它仅遵循 gulp-useref
parameters, but the files revisioned by gulp-rev
are not replaced by 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>
我发现了问题,gulp-rev-replace
文档提到他们默认只替换扩展名为 ['.js', '.css', '.html', '.hbs']
的文件。通过在 replaceInExtensions
选项中传递 ['.php']。