私はグラント用にincludereplaceプラグインを使用しようとしています。私は以下のコードを使用してJSONをフェッチすることによって、それはglobals
プロパティの値与えることをしようとしている:私はproperties.var_a
を行う際グランントでグローバルオブジェクトを作成
grunt.registerTask('fetchProperties', 'Fetches the properties.json file', function() {
properties = grunt.file.readJSON('properties.json');
grunt.log.writeln(['Properties file loaded']);
});
は、今では正しくvar_a
の値を返します。 だから、私はこのでした:ここ
grunt.registerTask('fetchProperties', 'Fetches the properties.json file', function() {
properties = grunt.file.readJSON('properties.json');
grunt.task.run('includereplace');
})
を私includereplaceタスクです:
includereplace: {
dist: {
options: {
globals: {
VAR_A: properties.var_a,
VAR_B: properties.var_b
},
},
files: [{
src: '../myFiles/path/to/some/file/main.txt',
dest: '../myOtherFiles/path/to/some/file/mainrep.txt'
}]
}
}
今includereplace
タスクによって置き換えられている値がundefined
です。 この問題を緩和するにはどうすればよいですか? また、私はgrunt.config
を使って変数を設定しようとしましたが、実際にはロード時に単一の値ではなくオブジェクトを返すJSONファイルがあります。実行時のすべてのタスクがそのパラメータを設定するために使用できるグローバルオブジェクトを設定するには? gruntファイルの先頭にJSONファイルをロードしています。それは私の中の最初の行ですmodule.exports = function(grunt) { ...