requireJS整个文件夹 [英] requireJS an entire folder

查看:49
本文介绍了requireJS整个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用requireJS要求"整个文件夹.

Is it possible to "require" an entire folder using requireJS.

例如,我有一个带有大量行为js文件的behaviors文件夹.我真的很想能够简单地使用require(['behaviors/*'],function(){...});加载该文件夹中的所有内容,而不必保持该列表为最新状态.压缩和优化后,我会将所有这些文件放在一起,但是对于开发而言,单独使用它们会更容易.

For example, I have a behaviors folder with a ton of behavior js files. I'd really like to be able to simply use require(['behaviors/*'], function() {...}); to load everything in that folder rather than having to keep that list up to date. Once compressed and optimized I'd have all those files lump together, but for development it's easier to work with them individually.

推荐答案

javascript没有文件系统访问权限,因此无法扫描目录中的文件.如果您使用php或ruby等脚本语言来构建应用程序,则可以编写一个脚本来扫描目录并将文件名添加到require()调用中.

javascript in browser has no filesystem access and so it can't scan a directory for files. If you are building your app in a scripting language like php or ruby you could write a script that scans the directory and adds the file names to the require() call.

这篇关于requireJS整个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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