【问题标题】:Injecting code into AngularJS file using grunt task使用 grunt 任务将代码注入 AngularJS 文件
【发布时间】:2015-02-02 20:03:29
【问题描述】:

我正在尝试将代码注入到我的 app.js 文件中,当我运行“grunt serve”任务时将触发该代码。在我的本地环境中运行应用程序时,只需要存在两行 javascript,但我不确定如何获取代码。我试过这个插件无济于事:https://github.com/ChrisWren/grunt-inject。感谢您的帮助!

【问题讨论】:

    标签: javascript angularjs gruntjs task


    【解决方案1】:

    使用grunt-preprocess,您可以有条件地在 html/js/css/anything 中添加部分代码...

    文档示例:

    仅当您在 GruntFile 中设置 DEBUG 变量时,script.tpl.js 文件才会被处理为带有 someDebuggingCall() 行的 script.js

    // @ifdef DEBUG
    someDebuggingCall()
    // @endif
    someCode()
    

    gruntFile.js 包含:

    preprocess : {
      options: {
        context : {
          DEBUG: true
        }
      },
      js : {
        src : 'script.tpl.js',
        dest : 'script.js'
      }
    }
    

    查看文档了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 2014-07-30
      • 2015-12-11
      相关资源
      最近更新 更多