我有个体型很差的人。里面有grunt-bump
和grunt-replace
。每次运行时,我都会使用grunt-bump
在pkg.json
中升级一个版本。而且每次运行grunt-replace
时,我都想用pkg.json
版本号替换index.js
版本。然而,我不能重复这样做,因为一旦变量`@@package被替换,变量就不再存在了。
Gruntfile.js:
module.exports = function(grunt) {
grunt.initconfig({
pkg: grunt.file.readjson('package.json'),
bump: {
options: {
files: ['package.json'],
updateconfigs: [],
commit: false,
commitmessage: 'release v%version%',
commitfiles: ['package.json'],
createtag: false,
tagname: 'v%version%',
tagmessage: 'version %version%',
push: false,
pushto: 'upstream',
gitdescribeoptions: '--tags --always --abbrev=1 --dirty=-d',
globalreplace: false,
prereleasename: false,
metadata: '',
regexp: false
}
},
replace : {
dist : {
options : {
patterns : [
{
match: 'packageJsonVersion',
replacement: '<%= pkg.version %>';
}
]
},
files : [
{
expand : true,
flatten : true,
src : [ 'index.html' ],
dest : './'
},
]
}
},
});
grunt.loadnpmtasks('grunt-bump');
grunt.loadnpmtasks('grunt-replace');
grunt.registertask('default', ['uglify']);
};
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="index.@@packageJsonVersion.js"></script>
</body>
</html>
发布于 2016-11-14 05:18:31
通常,我在src
文件夹中有包含要替换的变量的基本index.html
文件,但实际上我会复制该文件并在build
文件夹(或实际上包含您的prod静态资源的任何文件夹)中执行替换。这样,基本文件就永远不会被更改。
也许你可以改变dest
,让你的web服务器指向你的index.html的prod版本?
files : [
{
expand : true,
flatten : true,
src : [ 'index.html' ],
dest : 'build/index.html'
},
]
https://stackoverflow.com/questions/40553712
复制相似问题