【问题标题】:Grunt: Automatically adding script tagsGrunt:自动添加脚本标签
【发布时间】:2015-03-05 02:14:05
【问题描述】:

这可能是一个愚蠢的问题,但我对使用 grunt 还是很陌生。我已经使用 angular yeoman 生成器搭建了一个应用程序。在 index.html 我注意到这样的行:

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<!-- endbuild -->

当我将文件添加到开箱即用的脚本目录时,有没有办法自动添加新的脚本标签,还是我需要使用grunt-file-blocks之类的东西?

【问题讨论】:

    标签: javascript gruntjs yeoman


    【解决方案1】:

    一种方法是使用grunt-script-link-tags 插件here

    假设您的所有脚本都在 scripts 目录中,您可以将其添加到您的 Gruntfile.js

    tags: {
        build: {
            src: [
                'scripts/**/*.js'
            ],
            dest: 'index.html'
        }
    }
    

    然后将其添加到您的 index.html

    <!-- start auto template tags -->
    <!-- end auto template tags -->
    

    结果将是脚本(和子文件夹)中的所有*.js 文件都将插入到index.html 中的新script 标记中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2020-07-24
      • 2016-12-14
      相关资源
      最近更新 更多