gpt4 book ai didi

javascript - gulp-rev 为相同的代码库生成新文件名

转载 作者:行者123 更新时间:2023-11-28 04:21:57 29 4
gpt4 key购买 nike

正在使用yeoman angular generator (1.4.x)的代码库进行工作.

gulp-rev 正在被使用,即使对于相同的代码库,它每次都会生成一个新的文件(哈希)名称,我如何保留相同的文件哈希?

这是构建它的主要任务(我想),

gulp.task('html', ['inject', 'partials'], function () {
var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'), { read: false });
var partialsInjectOptions = {
starttag: '<!-- inject:partials -->',
ignorePath: path.join(conf.paths.tmp, '/partials'),
addRootSlash: false
};

var htmlFilter = $.filter('*.html', { restore: true });
var jsFilter = $.filter('**/*.js', { restore: true });
var cssFilter = $.filter('**/*.css', { restore: true });

return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
.pipe($.inject(partialsInjectFile, partialsInjectOptions))
.pipe($.useref())
.pipe(jsFilter)
.pipe($.sourcemaps.init())
.pipe($.ngAnnotate())
.pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))
.pipe($.rev())
.pipe($.sourcemaps.write('maps'))
.pipe(jsFilter.restore)
.pipe(cssFilter)
// .pipe($.sourcemaps.init())
.pipe($.replace('../../bower_components/bootstrap-sass/assets/fonts/bootstrap/', '../fonts/'))
.pipe($.cssnano())
.pipe($.rev())
// .pipe($.sourcemaps.write('maps'))
.pipe(cssFilter.restore)
.pipe($.revReplace())
.pipe(htmlFilter)
.pipe($.htmlmin({
removeEmptyAttributes: true,
removeAttributeQuotes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true
}))
.pipe(htmlFilter.restore)
.pipe(gulp.dest(path.join(conf.paths.dist, '/')))
.pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true }));
});

样式任务

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');

var browserSync = require('browser-sync');

var $ = require('gulp-load-plugins')();

var wiredep = require('wiredep').stream;
var _ = require('lodash');

gulp.task('styles-reload', ['styles'], function() {
return buildStyles()
.pipe(browserSync.stream());
});

gulp.task('styles', function() {
return buildStyles();
});

var buildStyles = function() {
var sassOptions = {
outputStyle: 'expanded',
precision: 10
};

var injectFiles = gulp.src([
path.join(conf.paths.src, '/app/**/*.scss'),
path.join('!' + conf.paths.src, '/app/app.scss')
], { read: false });

var injectOptions = {
transform: function(filePath) {
filePath = filePath.replace(conf.paths.src + '/app/', '');
return '@import "' + filePath + '";';
},
starttag: '// injector',
endtag: '// endinjector',
addRootSlash: false
};


return gulp.src([
path.join(conf.paths.src, '/app/app.scss')
])
.pipe($.inject(injectFiles, injectOptions))
.pipe(wiredep(_.extend({}, conf.wiredep)))
.pipe($.sourcemaps.init())
.pipe($.sass(sassOptions)).on('error', conf.errorHandler('Sass'))
.pipe($.autoprefixer()).on('error', conf.errorHandler('Autoprefixer'))
.pipe($.sourcemaps.write())
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app/')));
};

脚本任务

'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');

var browserSync = require('browser-sync');

var $ = require('gulp-load-plugins')();


gulp.task('scripts-reload', function() {
return buildScripts()
.pipe(browserSync.stream());
});

gulp.task('scripts', function() {
return buildScripts();
});

function buildScripts() {
return gulp.src(path.join(conf.paths.src, '/app/**/*.js'))
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.size())
};

Found this piece在 gulp-rev github 页面上但是,我不擅长 gulp ,所以不知道要改变什么以及这里的任务在哪里。

最佳答案

gulp-rev 的既定目的是这样做:

Static asset revisioning by appending content hash to filenames unicorn.css → unicorn-d41d8cd98f.css

这个想法是能够缓存这些静态文件,但仍然向用户提供最新的代码。如果您不想修改 Assets ,只需将其从管道中取出即可:

return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
.pipe($.inject(partialsInjectFile, partialsInjectOptions))
.pipe($.useref())
.pipe(jsFilter)
.pipe($.sourcemaps.init())
.pipe($.ngAnnotate())
.pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', conf.errorHandler('Uglify'))
.pipe($.sourcemaps.write('maps'))
.pipe(jsFilter.restore)
.pipe(cssFilter)
// .pipe($.sourcemaps.init())
.pipe($.replace('../../bower_components/bootstrap-sass/assets/fonts/bootstrap/', '../fonts/'))
.pipe($.cssnano())
// .pipe($.sourcemaps.write('maps'))
.pipe(cssFilter.restore)
.pipe(htmlFilter)
.pipe($.htmlmin({
removeEmptyAttributes: true,
removeAttributeQuotes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true
}))
.pipe(htmlFilter.restore)
.pipe(gulp.dest(path.join(conf.paths.dist, '/')))
.pipe($.size({ title: path.join(conf.paths.dist, '/'), showFiles: true
}));

关于javascript - gulp-rev 为相同的代码库生成新文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45364879/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com