Grunt:自动添加脚本标签

Unk*_*wns 3 javascript gruntjs yeoman

这可能是一个愚蠢的问题,但我很擅长使用grunt.我有一个使用角度yeoman发生器的应用程序搭建.在index.html中我注意到这样的行:

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

有没有办法自动添加新脚本标签,因为我将文件添加到开箱即用的脚本目录中,或者我是否需要使用类似的东西grunt-file-blocks

Tom*_*Tom 6

一种方法是使用grunt-script-link-tags插件,这里

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

tags: {
    build: {
        src: [
            'scripts/**/*.js'
        ],
        dest: 'index.html'
    }
}
Run Code Online (Sandbox Code Playgroud)

然后将其添加到index.html:

<!-- start auto template tags -->
<!-- end auto template tags -->
Run Code Online (Sandbox Code Playgroud)

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