如何在 `cachebust.resources()` 创建了 `bundle.a3503174.js` 之后从 html 引用 `bundle.js`?
How to reference `bundle.js` from html after `cachebust.resources()` has created `bundle.a3503174.js`?
https://github.com/jhades/angularjs-gulp-example/blob/master/gulpfile.js 的 link 似乎生成了一个名为 bundle.a3503174.js
的捆绑文件,但是,它在 html 中被引用为 bundle.js
.这是如何运作的?尽管名称已使用 md5 校验和编号扩展,系统如何知道在哪里查看正确的捆绑文件?
问题中的 link 实际上使用 gulp-cachebust
来创建包,然后将 index.html 中对该包的引用重写为适当的文件名。关键在于以下代码行中的语句cachebust.references()
。
gulp.task('build', [ 'clean', 'bower','build-css','build-template-cache', 'jshint', 'build-js'], function() {
return gulp.src('index.html')
.pipe(cachebust.references())
.pipe(gulp.dest('dist')); });
因此,尽管 index.html 的 non-gulp 版本中的引用 link 是 /dist/js/bundle.js
。该引用在 index.html 的 gulp 版本中被重写为 js/bundle.a3503174.js
。
https://github.com/jhades/angularjs-gulp-example/blob/master/gulpfile.js 的 link 似乎生成了一个名为 bundle.a3503174.js
的捆绑文件,但是,它在 html 中被引用为 bundle.js
.这是如何运作的?尽管名称已使用 md5 校验和编号扩展,系统如何知道在哪里查看正确的捆绑文件?
问题中的 link 实际上使用 gulp-cachebust
来创建包,然后将 index.html 中对该包的引用重写为适当的文件名。关键在于以下代码行中的语句cachebust.references()
。
gulp.task('build', [ 'clean', 'bower','build-css','build-template-cache', 'jshint', 'build-js'], function() {
return gulp.src('index.html')
.pipe(cachebust.references())
.pipe(gulp.dest('dist')); });
因此,尽管 index.html 的 non-gulp 版本中的引用 link 是 /dist/js/bundle.js
。该引用在 index.html 的 gulp 版本中被重写为 js/bundle.a3503174.js
。