如何根据mimosa中的构建配置文件将变量传递给coffeescript

如何根据mimosa中的构建配置文件将变量传递给coffeescript,coffeescript,global-variables,preprocessor,mimosa,Coffeescript,Global Variables,Preprocessor,Mimosa,我有一个典型的含羞草前端项目,带有用于脚本编写的coffeescript。我希望某个变量(api路径)具有不同的值,具体取决于构建概要文件(dev或prod)。我怎样才能在含羞草中做到这一点 我想要的示例: 生产咖啡: exports.api = 'myserver' exports.api = 'localhost' 开发咖啡: exports.api = 'myserver' exports.api = 'localhost' api访问器。咖啡 config = getCurren

我有一个典型的含羞草前端项目,带有用于脚本编写的coffeescript。我希望某个变量(api路径)具有不同的值,具体取决于构建概要文件(dev或prod)。我怎样才能在含羞草中做到这一点

我想要的示例:

生产咖啡:

exports.api = 'myserver'
exports.api = 'localhost'
开发咖啡:

exports.api = 'myserver'
exports.api = 'localhost'
api访问器。咖啡

config = getCurrentConfig(); # this is the part I do not know how to implement
exports.getStuff = () ->
  # here I want config.api to have different values depending on build profile
  $.ajax config.api + 'getStuff'

您可以将环境变量放入构建配置文件中

因此,不要使用
exports.api=“localhost”
,而是使用
process.env.api=“localhost”

然后,当使用该配置文件时,这些变量被附加到
env
并可在任何地方访问


这就是我们解决这类问题的方法。

我通过编写一个简单的含羞草来实现我的目标。 有了它我可以写作

/%= api %/
并将其替换为配置中的值