grunt-usemin不使用已修改的文件行替换参考块 [英] grunt-usemin not replacing reference block with revved file line

查看:104
本文介绍了grunt-usemin不使用已修改的文件行替换参考块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在grunt-usemin上遇到了一个问题,即它不会用单条修订的行替换未修订的参考块.在参考块中的两个文件被连接并丑化了;单个文件meta.min.js也获得很好的版本;但是,对修订后的文件的引用不会插入到index.html 中.只是未删除的行.

I've been having an issue with grunt-usemin where it doesn't replace the non-revved reference block with the single revved line. The two files in the reference block get concatenated and uglified just fine; the single file metadata.min.js also gets versioned just fine; but, the reference to the revved file doesn't get inserted in to index.html. Just the non-revved line.

我正在使用:

  • grunt-usemin 2.6.0
  • grunt-filerev 2.1.1
  • 用于模板化的Zend框架(因此有奇怪的模板路径)

这是在运行strong构建之前的之前的index.html参考块:

Here's the index.html reference block before running grunt build:

<!-- build:js js/dest/metadata.min.js -->
<script src="js/metadata/MetadataController.js"></script>
<script src="js/metadata/MetadataService.js"></script>
<!-- endbuild -->

以下是相关的Grunt配置:

Here's the relevant Grunt config:

useminPrepare: {
  html: '../cdm_common/cdm/layouts/scripts/index.html',
  options: {
    dest: 'dist',
    root: '.'
  }
},

filerev: {
  options: {
    encoding: 'utf8',
    algorithm: 'md5',
    length: 8
  },
  js: {
    src: ['dist/js/dest/*.js'],
    dest: 'js/dest/rev/test'
  }
},

usemin: {
  html: '../cdm_common/cdm/layouts/scripts/index.html',
  options: {
    assetsDirs: ['js/dest/rev/test']
  }
},

grunt.registerTask('build' ['useminPrepare','concat:generated','uglify:generated','filerev','usemin']);

这里是index.html 运行之后的:

Here's the index.html after running grunt build:

<script src="js/dest/metadata.min.js"></script>

修订后的行为什么不应该是这样?

Any reason why the revved line shouldn't look like this?

<script src="js/dest/metadata.min.a5851d60.js"></script>

这是grunt-usemin的错误吗?配置在某处关闭了吗?尽管未真正回答,但这类似于: Usemin不替换HTML中的参考块

Is this a bug with grunt-usemin? Is a config off somewhere? Though not really answered, this is similar to: Usemin not replacing reference blocks in HTML

我的头靠在桌子上一阵子.任何见解都将不胜感激.

Been beating my head against the desk for awhile. Any insight is greatly appreciated.

推荐答案

我也遇到了这种情况,问题是由usemin块中没有正确的assetDirs引起的.您将要确保您的assetDirs数组包含已修订文件的父文件夹.

This occurred to me as well and the issue was caused by not having the correct assetDirs in the usemin block. You will want to make sure your assetDirs array contains the parent folder of your revved file.

assetDirs文档

这是目录列表,我们应该在该目录中开始查找当前查看的文件中引用的资产的修订版本.

This is the list of directories where we should start to look for revved version of the assets referenced in the currently looked at file.

usemin: {
    html: 'build/index.html',
    options: {
        assetsDirs: ['foo/bar', 'bar']
    }
}

假设在index.html中您引用了/images/foo.png,usemin将搜索/images/foo.png的修订版,在assetsDirs选项中的任何目录中都说/images/foo.12345678.png.

Suppose in index.html you have a reference to /images/foo.png, usemin will search for the revved version of /images/foo.png, say /images/foo.12345678.png in any directories in assetsDirs options.

换句话说,给定上面的配置,usemin将搜索以下文件之一的存在:

In others words, given the configuration above, usemin will search for the existence of one of these files:

foo/bar/images/foo.12345678.png

foo/bar/images/foo.12345678.png

bar/images/foo.12345678.png

bar/images/foo.12345678.png

@Billy Blaze应该能够通过将他的usemin块中的assertDirs更新为assetsDirs: ['js/dest/rev/test', 'public']

@Billy Blaze should be able to replace his custom blockReplacements function by updating the assertDirs in his usemin block to be assetsDirs: ['js/dest/rev/test', 'public']

这篇关于grunt-usemin不使用已修改的文件行替换参考块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆