Angularjs 吞咽替换任务不工作
我正在用AngularJS构建一个Ionic应用程序,我有一个吞咽任务,应该替换文件中的数据。任务执行时没有错误,但不会替换它要替换的数据。好像什么都没有执行Angularjs 吞咽替换任务不工作,angularjs,ionic-framework,gulp,Angularjs,Ionic Framework,Gulp,我正在用AngularJS构建一个Ionic应用程序,我有一个吞咽任务,应该替换文件中的数据。任务执行时没有错误,但不会替换它要替换的数据。好像什么都没有执行 gulp.task('replace', function () { // Get the environment from the command line var env = args.env || 'localdev'; // Read the settings from the right file var
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"
}
在替换APIRL值时,它应该创建并发送到destination.js/services/constants.js,但它也不会创建该值
任何建议,因为我真的看不出代码有什么问题。谢谢你的帮助 我认为你应该改变路线:
gulp.src(paths.replace)
致:
或者告诉我们当前路径的值。替换。假设您使用的参数是错误的
它应该是replace(模式,替换)
另外,我认为在您的示例中,match
值是错误的。它将替换键和值。您需要在匹配器中使用@
换成
.pipe(replace('@@apiUrl', settings.apiUrl))
如果您需要替换多个对象,请将更多调用链接到replace()
假设使用了
gulp replace task
,我得到了相同的结果,任务执行时没有错误,但没有发生数据替换
env: windows
node: v10.14.1
gulp: 3.9.1
最后我求助于使用
因此,在上述代码中,代码类似于:
applause = require('applause'),
....
var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));
var options = {
patterns: [
{
match: 'apiUrl',
replacement: settings.apiUrl
}
]
};
var applauseRunner = applause.create(options);
var result = applauseRunner.replace(content);
// Do something with the result.content (i.e. pipe to stream)
希望这对其他人有所帮助。是源文件,你给出的是正确的吗?你的代码中是否使用了
replace()
替换?我相信在这个例子中使用的插件是基于.path.replace的。它在d时刻有“/js/constants.js”你得到console.log()的任何输出吗
您已经添加了?是的,控制台输出是正确的,但奇怪的是,它没有改变,也没有创建dest文件。我没有提到我在遵循本教程,我相信本例中使用的插件基于
env: windows
node: v10.14.1
gulp: 3.9.1
applause = require('applause'),
....
var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));
var options = {
patterns: [
{
match: 'apiUrl',
replacement: settings.apiUrl
}
]
};
var applauseRunner = applause.create(options);
var result = applauseRunner.replace(content);
// Do something with the result.content (i.e. pipe to stream)