【问题标题】:Adding <base href="/"> In AJS apps在 AJS 应用程序中添加 <base href="/">
【发布时间】:2015-07-29 06:01:45
【问题描述】:

我无法在 dist 文件夹的 index.html 中添加以下内容:

 <base href="/"> 

在头标签之后。我如何使用 grunt 任务来做到这一点?

参考:https://docs.angularjs.org/error/$location/nobase

【问题讨论】:

  • 只需手动将其粘贴到 index.html 的模板中?
  • no..我希望它在构建期间而不是在开发期间包含在内。那么我该如何为它编写 grunt 任务呢?

标签: angularjs twitter-bootstrap gruntjs


【解决方案1】:

您可以使用grunt-processhtml 仅在使用template-block 构建后添加&lt;base&gt;-元素

<!-- build:template
<base href="/">
/build -->

在您使用grunt-processhtml 处理文件之前,请注意模板块是如何被注释掉的。如果您想将 href-values 更改为根以外的其他值,您可以选择添加模板值。

<!-- build:template
<base href="/<%= basehref %>">
/build -->

配置:

  processhtml: {
    build: {
      options: {
        data: {
          basehref: ''
        }
      },
      files: {
        'dist/index.html': ['index.html']
      }
    }
  }

【讨论】:

  • 我应该在哪里添加这个配置?在哪个文件中?我尝试添加 gruntfile.js 并引发错误
  • @Smitha 你记得用npm install grunt-processhtml 安装它吗?错误是什么?
  • 现在它没有抛出错误但它没有添加任务。我确实安装了进程 html
  • 您能否在您的 Gruntfile(的相关部分)中进行编辑,会有所帮助。还可以尝试使用 --verbose-flag (grunt --verbose) 运行 grunt 以查看更多有用的输出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-05
  • 2016-12-07
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多