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

查看:11
本文介绍了构建纯离线 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.

我也注意到了独立的 blaze 项目,但我想利用 Meteor 的功能(开发过程中的热代码推送、包、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.

  • Meteor 在建立 DDP 连接时有点用力,所以它被设为 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.

自从引入 Cordova 系统以来,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) 在 bundle 中有一个目录在 /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.

其他注意事项:

  • 对图像、字体和其他文件使用基于文件的 html 路径(file.jpg 而不是/images/file.jpg)

  • 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中你不会用到的多余包,比如autoupdate

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天全站免登陆