包括在目录中的angularjs一个HTML文件中的所有JavaScript文件?与咕噜? [英] Include all javascript files in a directory to a html file in angularjs? with grunt?

查看:176
本文介绍了包括在目录中的angularjs一个HTML文件中的所有JavaScript文件?与咕噜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的AngularJS应用程序,我有很多的控制器js文件。

In my AngularJS app, I've many controllers js files.

这些控制器( one.ctrl.js two.ctrl.js ... )需要被包含在我的 index.html的文件。

These controllers (one.ctrl.js,two.ctrl.js,...) needs to be included in my index.html file.

目录结构:

app/
   js/
      controllers/
         one.ctrl.js
         two.ctrl.js

目前,上述 JS 文件都包含在 index.html的文件如下:

Currently, above js files are included in index.html file as follows.

index.html的:

<!--   other html components   -->

<script src="js/controllers/one.ctrl.js"/>
<script src="js/controllers/two.ctrl.js"/>
</body>
</html>

有会是更加 *这些都要求包含在 index.html的。ctrl.js 文件

There are gonna be more *.ctrl.js files which are required to be included in index.html.

我需要一种方法来自动包括所有的 *。ctrl.js 文件控制器目录 index.html的

I need a way to automatically include all the *.ctrl.js files in controllers directory to index.html.

结果:

从一些SO问题,

<一个href=\"http://stackoverflow.com/questions/22605770/load-javascript-and-css-files-in-folders-in-angularjs\">Load JavaScript和CSS文件的文件夹AngularJS

<一个href=\"http://stackoverflow.com/questions/4175008/how-can-i-include-all-javascript-files-in-a-directory-via-javascript-file\">How我可以包括通过JavaScript目录中的所有文件的JavaScript文件?

我发现,它不能自动完成,需要一些服务器端脚本或构建工具。

I found that it cannot be done automatically and needs some server side scripting or build tools.

我的问题:

目前,我使用自耕农包括咕噜的构建工具。
所以,我的问题是,如何才能在这些目录中的JavaScript文件被自动包含在HTML文件?

Currently, I'm using yeoman which include grunt for build tool. So, my question is, How can those javascript files in a directory be automatically included in a html file?

推荐答案

您可以使用咕噜,包括源插件

使用它,你可以定义这样的模板:

Using it you can define templates like these :

html: {
    js: '<script src="{filePath}"></script>',
    css: '<link rel="stylesheet" type="text/css" href="{filePath}" />',
  }

在你的HTML文件,该文件将扩大到包括在源位置的所有源js和css文件present可在繁重的任务进行配置

in your html file which will be expanded to include all your source js and css files present in your source location which can be configured in the grunt task

这篇关于包括在目录中的angularjs一个HTML文件中的所有JavaScript文件?与咕噜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆