【问题标题】:Grunt - Get variable exported in the environemnt to string in a fileGrunt - 将环境中导出的变量获取到文件中的字符串
【发布时间】:2016-11-22 22:28:26
【问题描述】:

您好,我想做一个简单的任务:

在linux中导出一个变量:

export API = "http://127.0.0.1:999"

然后用 grunt 脚本获取它。

并在我的 apiService 中替换一行。

目前我无法 console.log 环境变量:

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    destination: process.env.API,

  grunt.loadNpmTasks('grunt-envpreprocess');
  grunt.registerTask('default',['watch']);

  console.log("here: " + process.env.API);
};

有人可以帮我弄清楚该怎么做吗?

谢谢

【问题讨论】:

    标签: angularjs node.js gruntjs


    【解决方案1】:

    你没有关闭大括号(LN5),试试这样:

    const grunt = require('grunt');
    
    module.exports = function(grunt) {
      grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        destination: process.env.API || 'none',
      });
    
      grunt.registerTask('default', () => {
        console.log("here: ", grunt.config.get('destination'));
      });  
    };
    

    【讨论】:

    • 这不是问题
    猜你喜欢
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 2015-06-18
    • 1970-01-01
    相关资源
    最近更新 更多