如何访问角常数咕嘟咕嘟文件? [英] How to access Angular constant in Gulp file?

查看:118
本文介绍了如何访问角常数咕嘟咕嘟文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有我们可以咕嘟咕嘟文件访问角不变的方式?

Is there a way we can access Angular constant in Gulp file?

一个例子是:

angular.module('app').constant('env', {
    url: 'http://localhost:1337/'
});

我如何访问咕嘟咕嘟任务这里面的功能?

How can I access this inside function of Gulp task?

推荐答案

您无法访问咕嘟咕嘟这样的事情 - 但如果你改变你如何思考这个问题,你可以

You can't access things like this from Gulp -- but if you change how you're thinking about the problem, you can.

很明显,你需要访问的配置在不同的上下文 - 你的角度应用程序内,里面你一饮而尽构建任务,等等。

It's clear that you need to access configuration in different contexts -- inside your angular app, inside your gulp build tasks, etc.

相反,具有角常量的文件,为什么不把你的配置的JSON文件?

Instead of having an Angular constants file, why not have a JSON file of your configuration?

我有这个同样的问题,为我的项目而导致我建立吞掉-NG之一-config 。我创建了一个JSON文件我的配置,然后用这个一饮而尽插件生成我的角度常量,但也让我访问配置,但是我会需要它里面一饮而尽。这里有一个例子:

I had this same problem for one of my projects which lead me to build gulp-ng-config. I created a JSON file for my configuration, and then used this gulp plugin to generate my angular constants, but also allowed me to access the configuration for however I'd need it inside gulp. Here's an example:

var gulp = require('gulp');
var ngConfig = require('gulp-ng-config');

gulp.task('constants', function () {
  return gulp.src('./config.json')
  .pipe(gulpNgConfig('myApp.config')
  .pipe(gulp.dest('src/config.js'));
});

// and if you need the configuration directly
var config = require('./config.json');
console.log(config.foobar);

gulpNgConfig 将创建一个名为角模块 myApp.config 用一组中定义的常量你的 config.json 。有关更多示例,请查看自述

gulpNgConfig will create an angular module with the name myApp.config with a set of constants that were defined in your config.json. For more examples, check out the readme.

这篇关于如何访问角常数咕嘟咕嘟文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆