简体   繁体   English

如何在没有服务器的情况下使用ember.js

[英]how to use ember.js without server

I am following the ember.js example on this site (http://todomvc.com/) . 我正在该站点(http://todomvc.com/)上的ember.js示例中。 I clone this project to my computer and just double click index.html and it runs, as what I expect. 我将此项目克隆到我的计算机上,只需双击index.html即可按预期运行。

But in ember's guide , it tells me to install the ember-cli, and create a new project, then build it. 但是在ember指南中 ,它告诉我安装ember-cli,创建一个新项目,然后构建它。

ember new myapp
ember build

I can find my files in /dist , but when I double click the index.html it fails. 我可以在/dist找到我的文件,但是当我双击index.html它将失败。

This post said, "You have to serve your directory with an http server." 这篇文章说:“您必须使用http服务器来提供目录。”

Why do I need a server to run this project, instead of just opening it in my browser? 为什么我需要一台服务器来运行该项目,而不仅仅是在浏览器中打开它?

The example that you linked is using the old global Ember. 您链接的示例使用的是旧的全局Ember。 This is very different from ember-cli which you are now working with. 这与您正在使用的ember-cli有很大不同。 An http server is required because of the <base> tag in the index.html file that specifies the base URL to use for all relative URLs contained within a document. 由于index.html文件中的<base>标记指定了要用于文档中包含的所有相对URL的基本URL,因此需要http服务器。 So when your app is trying to serve up the assets/app.js or assets/vendor.js , its trying to look relative to this base url, which is defined in config/environment.js . 所以,当你的应用程序要投放了assets/app.jsassets/vendor.js ,它试图寻找相对于该基地的URL,这是在定义config/environment.js It defaults to / . 默认为/ So you need a server to respond to the resource requests for the assets. 因此,您需要一台服务器来响应资产的资源请求。 Notice that your assets folder is relative to the index.html file 请注意,您的assets文件夹是相对于index.html文件的

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

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