构建一个纯粹的离线Meteor应用 [英] Building a pure offline Meteor app

查看:79
本文介绍了构建一个纯粹的离线Meteor应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在Stack Overflow上没有互联网连接时如何可以离线使用Meteor似乎存在一些问题,但是我对是否有可能构建仅会是 的Meteor应用程序感兴趣.离线使用.例如,是否可以生成一个文件夹,其中包含一个HTML文件和所有其他必需文件(图像以及可能的CSS文件和JavaScript文件(如果未嵌入HTML文件),并且所有文件都可以在开箱即用的情况下工作)在浏览器中打开HTML文件?

Seems to be some questions about how one can use Meteor offline when there's no internet connection here on Stack Overflow, but I'm interested in if it's possible to build a Meteor application that will only be used offline. For example, is it possible to generate folder containing a single HTML file and all other files necessary (images, and possible CSS files and JavaScript files if they aren't embedded into the HTML file), and everything works out of the box when one opens the HTML file in a browser?

据我测试,可以使用 appcache软件包(一个人处于联机状态时访问一次该页面,然后一个人处于脱机状态时可以访问该页面),但这似乎不可靠.

As far as I have tested, one can kind of getting it to work using the appcache package (one visits the page once when one is online, and then one can visit it when one is offline), but it seems unreliable.

我也注意到了独立的火焰项目,但我想利用流星的功能(开发期间的热代码推送,软件包,minimongo等).

I've also noticed the stand alone blaze project, but I want to take advantage of Meteor's features (hot code pushes during development, packages, minimongo, etc.).

那么,有人知道我想做的事是否可以通过某种方式实现吗?

So, does anyone know if what I want to do is achievable in some way?

推荐答案

您可以构建一个完全脱机的Meteor应用程序,但有一些怪异"的折衷办法.

You can build a purely offline Meteor app but there are a few 'weird' compromises.

  • 在建立DDP连接时,Meteor有点强大,因此由于没有服务器,因此将它作为127.0.0.1进行空环回.

  • Meteor is a bit forceful when it comes to making a DDP connection, so it is made to 127.0.0.1 as a sort of null loopback, since there is no server.

Meteor已经以这种仅脱机的方式构建了该应用程序,因此它只是将其提取出来了.有serverweb.cordovabrowser的版本.

Meteor already builds the app in this offline-only way since the Cordova system was introduced, so its just extracting that out pretty much. There are builds for server, web.cordova and browser.

1)捆绑您的应用并将其提取出来

1 ) Bundle your app and extract it out

我将在todo应用程序中随机制作一个示例(它需要服务器端的位,但是请忽略掉它)

I'll just make a random example out of the todo app (it requires a server side bit, but well ignore that)

meteor create --example todos
cd todos
meteor bundle ~/Desktop/app.tar.gz
cd Desktop
tar xvzf app.tar.gz

2)在捆绑包中,在/programs/web.browser处有一个目录,这是您的脱机应用程序的框架,因此请将该目录放置在某个位置.

2) In bundle there is a directory at /programs/web.browser, this is the framework of your offline app so take that directory and put it somewhere.

3)有两个文件,文件名带有哈希值.将它们重命名为app.jsapp.css

3) There are two files with a hash as the filename. Rename them as app.js and app.css

4)有一个名为app的目录.将其所有内容上移到主目录,即

4) There is a directory called app. Move all its contents up to the main directory, i.e

cd app
mv * ../
rm -r app

5)创建一个包含以下内容的index.html文件:

5) Create a index.html file with the following in it:

<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="app.css?meteor_css_resource=true">
    <script type="text/javascript">
    __meteor_runtime_config__ = {
        "meteorRelease": "1.0.0",
        "ROOT_URL": "/",
        "ROOT_URL_PATH_PREFIX": "",
        "autoupdateVersion": "00000",
        "DDP_DEFAULT_CONNECTION_URL": "127.0.0.1"
    };
    </script>

    <script type="text/javascript" src="app.js"></script>

    <script type="text/javascript">
    if (typeof Package === 'undefined' ||
        !Package.webapp ||
        !Package.webapp.WebApp ||
        !Package.webapp.WebApp._isCssLoaded())
        console.log("Load Fail");
    </script>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0">
    <meta http-equiv="content-language" content="en">
    <meta name='apple-mobile-web-app-capable' content='yes' />
    <meta name='apple-mobile-web-app-status-bar-style' content='black' />
    <title>Your App</title>
</head>

<body>

</body>

</html>

和瞧!

请记住,此应用程序需要服务器,因此这种方式毫无用处,但是您可以根据需要制作一个纯粹的客户端应用程序.

Keep in mind this app needs a server so its quite useless this way, but you can make a purely client side app if you wanted.

其他注意事项:

  • 为图像,字体和其他文件(file.jpg代替/images/file.jpg)使用基于文件的html路径

  • Use file based html paths for images, fonts and other files (file.jpg instead of /images/file.jpg)

使用铁路由器会有些棘手,但您不能使用/,而必须使用index.html和相对路径

With iron router its a bit tricky but you can't use / you'll have to use index.html and relative paths

您可以在meteor-platform中删除不使用的冗余软件包,例如自动更新

You can remove redundant packages in meteor-platform that you will not use, such as autoupdate

有一些软件包可以帮助数据存储,例如ground:db而不是需要服务器端的mongo集合.

There are a few packages on atmosphere that help with data storage such as ground:db instead of mongo collections which require a server side.

这篇关于构建一个纯粹的离线Meteor应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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