问题描述
当你使用 Meteor 框架创建一个项目时,它会将所有文件打包在一起,但似乎没有一种方法可以明确地说我希望在那个文件之前加载这个文件".
When you make a project with the Meteor framework, it packages all the files together, but there doesn't seem to be a way to explicitly say "I want this file to be loaded before that one".
假设,例如,我有 2 个 javascript 文件:foo.js
和 bar.js
.
Let's say, for example, I have 2 javascript files: foo.js
and bar.js
.
文件 bar.js
实际上包含依赖于 foo.js
内的代码,但 Meteor 在 bar.js
之前加载 bar.js
code>foo.js,破坏项目.
The file bar.js
is actually containing code depending one the one inside foo.js
but Meteor is loading bar.js
before foo.js
, breaking the project.
- 在 node.js 中,我会在
foo.js
中简单地使用 - 在浏览器中,我将放置一个指向
foo.js
的<script>
标记和另一个指向bar.js
,以便以正确的顺序加载文件.
require('./bar')
- In node.js I would simply use
require('./bar')
insidefoo.js
- In the browser, I would put a
<script>
tag pointing tofoo.js
and another, after, pointing tobar.js
, in order to load the files in the correct order.
我们如何在 Meteor 中做到这一点?
How can we do that in Meteor?
推荐答案
根据 Meteor 文档,目前文件是按这个顺序加载的:
According to the Meteor documentation, files are currently loaded in this order:
- 首先加载 [project_root]/lib 中的文件
- 文件按目录深度排序.首先加载更深的文件.
- 文件按字母顺序排序.
- main.* 文件最后加载.
来源:http://docs.meteor.com/#structuringyourapp
这篇关于如何更改 Meteor 加载 Javascript 文件的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!