问题描述
我最近正在研究流星,它绝对方便又强大.但是到目前为止,仍然不清楚Meteor APP的入口是什么,换句话说,哪个文件/功能将首先执行?
I am recently studying Meteor which is absolutely convenient and powerful. But so far it is still not clear what is the entry point of a Meteor APP, in other words, which file/function will be executed first?
一个简单的例子:
client/hello.jsx:
client/hello.jsx:
import React from 'react';
export const Welcome = ({name}) => (
<div>
Hello, {name}.
</div>
);
client/routes.jsx:
client/routes.jsx:
import React from 'react';
import {mount} from 'react-mounter';
import {Layout, Welcome} from './hello.jsx';
FlowRouter.route("/", {
action() {
mount(Layout,
{content: (<Welcome name="My Shining Name" />)}
);
}
});
然后我使用命令:
然后将启动一个网页!看起来很神奇:服务器在哪里运行?网页是如何生成的?最重要的是,哪一段代码将首先执行?
Then a webpage is launched! It looks pretty magic: where is the server running? how the webpage is generated? Most importantly, which piece of code will be executed first?
谢谢
德里克
推荐答案
Meteor捆绑了源客户端文件,并将其分发给客户端.在此过程中,JS可能会被转译,样式表可能会自动添加前缀.最后,客户端执行捆绑软件.
Meteor bundles source client files and ships the bundle to the client. JS may be transpiled, and style sheets may be auto-prefixed during the process. At the end, the client executes the bundle.
源客户端文件是指名为'client'的文件夹中的文件.这些源文件按此文档中所述的顺序执行,引用如下.
A source client file refers to a file in a folder named 'client'. Those source files are executed in an order described in this document, quoted as below.
- HTML模板文件总是先加载
- 以main开头的文件.最后加载
- 接下来将加载任何lib/目录中的文件
- 具有更深路径的文件接下来将被加载
- 然后按照整个路径的字母顺序加载文件
- HTML template files are always loaded before everything else
- Files beginning with main. are loaded last
- Files inside any lib/ directory are loaded next
- Files with deeper paths are loaded next
- Files are then loaded in alphabetical order of the entire path
鉴于此列表,对于文件结构 的初步了解至关重要.在这种理解下,例如,Meteor应用程序应该将哪个文件转到何处(客户端/服务器),以及急切加载哪些文件,这对于决定如何构建应用程序至关重要.
Given the list, it's critical to build yourself some preliminary knowledge about the file structure of a Meteor application in that understanding, say, which file goes to where (client/serer) and which files are eagerly loaded is crucial to deciding how to structure an application.
回到您的应用程序.所显示的网页实质上是包含另一个React组件Welcome
的React组件Layout
.它们通过react-mounter
安装到HTML模板中的DOM节点上,我相信在您的示例应用程序中是一个名为"client/index.html"或"client/hello.html"的文件.前述节点通常是具有指定id
属性的div
,或者是react-mount
在运行时创建的DOM节点.
Getting back to your application. The webpage you are presented is essentially the React component Layout
containing another React component Welcome
. They are mounted by react-mounter
onto a DOM node in a HTML template, which I believe in your example application is a file named 'client/index.html' or 'client/hello.html'. The aforementioned node is usually a div
with a specified id
attribute, or a DOM node created by react-mount
at run time.
说到服务器端,Meteor运行一个增值的HTTP Web服务器,以便在启动Meteor应用程序时使用 Meteor API 来编程所需的功能.
Speaking of the server side, Meteor runs a value-added HTTP web server for when you start a Meteor application, and you program the features you like to have with Meteor APIs.
我希望以上信息能帮助您继续使用Meteor构建应用程序.享受吧!
I hope the information above help you proceed with building applications with Meteor. Enjoy!
这篇关于Meteor APP的入口点/文件/功能是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!