【发布时间】:2015-06-11 03:49:51
【问题描述】:
我正在使用 AngularJS 构建一个 Ionic 应用程序,并且我有一个 gulp 任务应该替换文件中的数据。该任务执行没有错误,但它不会替换它要替换的数据。它就像什么都没有执行。
gulp.task('replace', function () {
// Get the environment from the command line
var env = args.env || 'localdev';
// Read the settings from the right file
var filename = env + '.json';
var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));
console.log(settings.apiUrl)
// Replace each placeholder with the correct value for the variable.
gulp.src(paths.replace)
.pipe(replace({
patterns: [
{
match: 'apiUrl',
replacement: settings.apiUrl
}
]
}))
.pipe(gulp.dest('./js/services'));
console.log("here")
});
js/constants.js 文件
angular.module('loanstreet.constants',[])
.constant('apiUrl', '@@apiUrl');
localdev.json
{
"apiUrl":"http://10.0.3.2:3000"
}
在替换 apiUrl 值后,它应该创建并发送到目标 .js/services/constants.js 但它也不会创建它。
任何建议,因为老实说我看不出代码有什么问题。任何帮助表示赞赏。
【问题讨论】:
-
是源文件,你给出的正确吗?
-
你的代码中是否使用了
replace()gulp-replace? -
我相信本例中使用的插件是gulp-replace-task,它基于applause。
标签: angularjs ionic-framework gulp