简体   繁体   English

Meteor.js提供的JavaScript文件不带(function(){…})。call(this)

[英]Meteor.js serve javascript files without (function() { … }).call(this)

The title should be self explanatory, but is there a way to get Meteor to serve up a javascript file without stuffing it into (function() { <<code>> }).call(this) ? 标题应该是不言自明的,但是有没有办法让Meteor提供一个javascript文件而不将其填充到(function() { <<code>> }).call(this)

I wrote an app that relies on javascript objects each stored in their own file and then instantiated when they are ready to be used. 我编写了一个应用程序,该应用程序依赖每个存储在自己文件中的javascript对象,然后在准备使用时实例化。 However, because of the aforementioned problem, they are isolated and unable to be viewed from outside files. 但是,由于上述问题,它们是隔离的,无法从外部文件中查看。

The only option I have come up with is to store them as plaintext and then load them using an HTTP request and then store them into the main file. 我想到的唯一选择是将它们存储为纯文本,然后使用HTTP请求加载它们,然后将它们存储到主文件中。 Hopefully I am missing a much easier way. 希望我错过了一个更简单的方法。

If you need any code, let me know, but I think this is general enough to not warrant any. 如果您需要任何代码,请告诉我,但是我认为这很普遍,不能保证任何代码。

--EDIT-- - 编辑 -

I originally wrote this to be a standalone html page, but then decided to go all out and use meteor to make it a full-blown web app. 我最初将其编写为独立的html页面,但后来决定全力以赴,并使用流星使它成为功能完善的Web应用程序。

Its probably not a good idea to try and get the javascript file this way because when you deploy the app or set production mode on, all the javascript files and html files will be minified into a single js file & they wouldn't exist the normal locations during development anymore: 尝试以这种方式获取javascript文件可能不是一个好主意,因为当您部署应用程序或在其上设置生产模式时,所有javascript文件和html文件都将被压缩为一个js文件,并且它们通常不会存在开发期间的位置:

If you want the javascript file to be untouched by meteor you would need to put it in a folder called /public in your projects root directory. 如果您希望流星不更改javascript文件,则需要将其放在项目根目录中名为/public的文件夹中。

If you are more interested in whats inside the javascript files as opposed to getting them by filename you might want to switch to the devel branch of meteor, or wait for the never version after 0.6.2.1 and put your javascript files in /client/compatibility/ as these files are not variable scoped & will still be automatically referenced unlike the /public dir. 如果您对javascript文件中的内容更感兴趣,而不是通过文件名来获取它们,则可能要切换到流星的devel分支,或者等待0.6.2.1之后的never版本并将javascript文件放在/client/compatibility/因为这些文件的作用域不是变量,并且与/public目录不同,它们仍将被自动引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM