如何更改 Meteor 加载 Javascript 文件的顺序? [英] How do I change the order in which Meteor loads Javascript files?

查看:18
本文介绍了如何更改 Meteor 加载 Javascript 文件的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你使用 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.jsbar.js.

Let's say, for example, I have 2 javascript files: foo.js and bar.js.

文件 bar.js 实际上包含依赖于 foo.js 内的代码,但 Meteor 在 bar.js 之前加载 bar.jscode>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
  • 中简单地使用 require('./bar')
  • 浏览器中,我将放置一个指向foo.js<script>标记和另一个指向bar.js,以便以正确的顺序加载文件.
  • In node.js I would simply use require('./bar') inside foo.js
  • In the browser, I would put a <script> tag pointing to foo.js and another, after, pointing to bar.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:

  1. 首先加载 [project_root]/lib 中的文件
  2. 文件按目录深度排序.首先加载更深的文件.
  3. 文件按字母顺序排序.
  4. main.* 文件最后加载.

来源:http://docs.meteor.com/#structuringyourapp

这篇关于如何更改 Meteor 加载 Javascript 文件的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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