我試圖用/ mydir /替換HTML基本標記的href屬性值。已經嘗試過使用grunt-usemin的blockReplacements。不能用grunt-usemin的自定義塊替換HTML基本標記替換
下面是配置
// 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']
]
}
}
}
我的HTML正在調用usemin:
<!-- build:baseUrl /mydir/ -->
<base href="/">
<!-- endbuild -->
我運行:
$ grunt serve:dist
但這只是去掉了基本標記,並且不更換。 我有一個懷疑,我需要在Gruntfile中配置一個baseUrl屬性,但我不試圖修改/ uglify文件,並相信這個屬性會指向需要改變的文件等。
另外我試過運行調試發送grunt.log.debug調用buildReplace函數:
$ grunt --debug serve:dist
但是沒有控制檯輸出。
注意:我的應用程序基於角度全堆生成器應用程序。 https://github.com/angular-fullstack/generator-angular-fullstack
任何幫助或建議表示讚賞。
是不是'base'而不是'baseUrl'? – mika