【发布时间】:2016-03-05 08:06:05
【问题描述】:
我正在尝试将 HTML 基本标记的 href 属性值替换为 /mydir/。已尝试使用 grunt-usemin 的 blockReplacements 进行此操作。
这里是配置
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
html: ['<%= yeoman.client %>/index.html'],
options: {
dest: '<%= yeoman.dist %>/public'
}
},
// Performs rewrites based on rev and the useminPrepare configuration
usemin: {
html: ['<%= yeoman.dist %>/public/{,*/}*.html'],
css: ['<%= yeoman.dist %>/public/{,*/}*.css'],
js: ['<%= yeoman.dist %>/public/{,*/}*.js'],
options: {
assetsDirs: [
'<%= yeoman.dist %>/public',
'<%= yeoman.dist %>/public/assets/images'
],
blockReplacements: {
baseUrl: function (block) {
grunt.log.debug("******************* blockReplacements *******************");
return '<base href="/mydir/">';
}
},
// This is so we update image references in our ng-templates
patterns: {
js: [
[/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
]
}
}
}
我调用 usemin 的 html:
<!-- build:baseUrl /mydir/ -->
<base href="/">
<!-- endbuild -->
我正在跑步:
$ grunt serve:dist
但这只是删除了基础标签,并没有替换。 我怀疑我需要在 Gruntfile 中配置一个 baseUrl 属性,但我并没有尝试修改/修改文件,我相信这个属性会指向需要修改等的文件。
我也尝试过运行调试来触发 grunt.log.debug 调用 buildReplace 函数:
$ grunt --debug serve:dist
但是没有控制台输出。
注意:我的应用程序基于 Angular 全栈生成器应用程序。 https://github.com/angular-fullstack/generator-angular-fullstack
任何帮助或建议表示赞赏。
【问题讨论】:
-
不是
base而不是baseUrl吗?
标签: gruntjs grunt-usemin angular-fullstack