Thank you for the reply. Have you looks in the browser console after using this tool? I hardly believe it stays clean. All this tool does it builds the project, gets the content of web.browser
and replaces the index.html with taken from the template. After the main Meteor .js file execution it runs Meteor.disconnect()
(I do it even earlier, but it does not help). Here is the code from https://github.com/frozeman/meteor-build-client/blob/master/meteor.js
, which does that:
...
if(program.url !== 'default')
settings.ROOT_URL = program.url || '';
if(settingsJson.public)
settings.PUBLIC_SETTINGS = settingsJson.public;
scripts = scripts.replace('__meteor_runtime_config__', '<script type="text/javascript">__meteor_runtime_config__ = JSON.parse(decodeURIComponent("'+encodeURIComponent(JSON.stringify(settings))+'"));</script>');
// add Meteor.disconnect() when no server is given
if(!program.url)
scripts += ' <script type="text/javascript">Meteor.disconnect();</script>';
...
My own script (it is in BASH, so it is several times smaller) works a bit differently:
1. copy the full project to tmp
;
2. remove webapp
and hot-code-push
modules;
3. build the project;
4. add webapp
module;
5. run the project (with production settings);
6. grab index file (or a set of files if the app is router-enabled) by PhantomJS;
7. replace paths to .js and .css files and the value of __meteor_runtime_config__
within grabbed files. DDP_DEFAULT_CONNECTION_URL
is set to https://none
here;
8. put the resulting html files together with .css, .js and content of public directory into the output directory.
As the result I have a set of pages, which work even when javascript is disabled on the client (well, with understandable limitations). This set of files is ready to be deployed to S3 or GitHub Pages or GitLab Pages (as I do) or anything else.
However, I have an error in the browser console, which tells that none
server-name could not be resolved. It does not look nice ;). To prevent further attempts to connect I have the following lines right in the beginning on the client index:
/* Disconnect from the server as the first step when running in production env */
/* global meteorEnv */
if( meteorEnv.NODE_ENV === "production" ) Meteor.disconnect()
Other files are imported as modules, so I am sure that these lines are executed before my other code. But unfortunately, meteor packages’ code is executed even further. I considered putting these lines in a separate package, however I doubt it will work. I suppose I cannot call disconnect()
before ddp
module is loaded as it will be unavailable yet. So, I have to dig further
If someone is interested in the script, I will “prettify” it and publish somewhere.