简体   繁体   English

通过离子服务将参数传递给gulp任务

[英]Pass parameters to gulp task through ionic serve

I am willing to switch easily between production and development environments in an Ionic project. 我愿意在Ionic项目中轻松切换生产和开发环境。 I have been following this guide : Environment Variables in Ionic and AngularJS 我一直在关注本指南: Ionic和AngularJS中的环境变量

It is pretty straightforward, the gulp task will replace the variables with the values defined in the appropriate JSON file, which is chosen depending on the parameter passed to the task. 它非常简单,gulp任务将使用相应JSON文件中定义的值替换变量,该文件根据传递给任务的参数进行选择。

My issue here is that I do not call Gulp directly, but I call it through ionic CLI (ionic serve). 我的问题是我不直接调用Gulp,但我通过离子CLI(离子服务)调用它。 I know that I can specify the gulp tasks to call in the ionic.project file, but how can I pass some parameters to the ionic CLI and have them piped to Gulp ? 我知道我可以在ionic.project文件中指定要调用的gulp任务,但是如何将一些参数传递给离子CLI并将它们传送给Gulp?

I would like to simply do : 我想简单地做:

ionic serve --prod
ionic serve --dev --lab

And it would select the proper values for my constants accordingly to the parameter. 它会根据参数为我的常量选择合适的值。

When you run ionic serve like so: 当你像这样运行离子服务时:

ENV=production ionic serve

in gulp to get ENV varaible 一口气让ENV变得可变

process.env.ENV

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM