• Stars
    star
    277
  • Rank 147,978 (Top 3 %)
  • Language
    JavaScript
  • Created over 9 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tool to bundle the client part of a Meteor app.

Meteor Build Client

Builder and bundler for the client part of a Meteor application. As a result it would generate simple index.html, so it can be hosted on any server or even loaded via the file:// protocol.

ToC:

Installation

npm install -g meteor-build-client

Important notes:

  • The Meteor/Atmosphere package frozeman:build-client is just a placeholder package, there's no need to install it;
  • Warning: the content of the output folder will be deleted before building the new output! So don't do things like meteor-build-client /home!
  • Do not use dynamic imports! e.g. import('/eager/file');;
  • By default this package link legacy ES5 bundle build; For ES6/Modern scripts build an app with meteor build <path> --exclude-archs web.browser.legacy --directory flag and pass it to --usebuild <path>, see docs

Output

The content of the output folder could look as follows:

  • index.html
  • a28817fe16898311635fa73b959979157e830a31.css
  • aeca2a21c383327235a08d55994243a9f478ed57.js
  • ... (other files from project's /public directory)

Usage

Things you need to know before exporting your project

Define where stylesheet links & script links will land

meteor-build-client looks for the <meteor-bundled-css /> tag in your <head> section and the <meteor-bundled-js /> tag in the <body> section.

Example:

<head>
  <!-- your header stuff... -->
  <!-- then typically add the css link at the bottom of the head -->
  <meteor-bundled-css />
</head>

<body>
  <!-- typically want to load all the js code at the top -->
  <meteor-bundled-js />
  <!-- The rest of your body stuff... -->
</body>

Note: this does not work for blaze projects. For blaze projects you can only set <meteor-bundled-css /> in your header. It is invalid to set <meteor-bundled-js /> in your body, simply leave it out and the right thing will happen.

Command line usage

List all available options and show docs:

meteor-build-client --help

Usage examples:

# cd to meteor app
cd /my/app

# run meteor-build-client
meteor-build-client ../output/directory

# build meteor app as usual
meteor build ../build-directory --directory
# bundle client-only assets with meteor-build-client
meteor-build-client ../build-directory-client --url https://example.com --usebuild ../build-directory

Passing a settings.json

Pass Meteor's settings.json settings file via --settings or -s option:

meteor-build-client ../output/directory -s ../settings.json

Note: Only the public property of that JSON file will be add to the Meteor.settings property.

App URL

Set the ROOT_URL of the application via --url or -u option:

meteor-build-client ../output/directory -u https://myserver.com

By passing "default", application will try to connect to the server from where the application was served. If this option was not set, it will set the server to "" (empty string) and will add a Meteor.disconnect() after Meteor was loaded.

Absolute or relative paths

To serve application via file:// protocol (by opening the index.html) set --path or -p option to "" (empty string). This would generate relative paths for assets across the application:

meteor-build-client ../output/directory -p ""

The default path value is "/".

Note: "path" value will replace paths in generated CSS file. Use it to link fonts and other assets correctly.

Using your own build folder

To use pre-build Meteor application, built using meteor build command manually, specify the --usebuild <path-to-build> flag and meteor-build-client will not run the meteor build command.

Best practices

Tips'n tricks using client bundle

Recommended packages for client-only build

When building server-less standalone web application we recommend to replace meteor-base with meteor and webapp packages.

@@ .meteor/packages
- meteor-base
+ meteor
+ webapp

Connecting to a Meteor server

In order to connect to a Meteor servers, create DDP connection by using DDP.connect(), as seen in the following example:

// This Should be in both server and client in a lib folder
DDPConnection = (Meteor.isClient) ? DDP.connect('http://localhost:3000/') : {};

// When creating a new collection on the client use:
if(Meteor.isClient) {
  posts = new Mongo.Collection('posts', DDPConnection);

  // set the new DDP connection to all internal packages, which require one
  Meteor.connection = DDPConnection;
  Accounts.connection = Meteor.connection;
  Meteor.users = new Mongo.Collection('users');
  Meteor.connection.subscribe('users');

  // Subscribe like this:
  DDPConnection.subscribe('mySubscription');
}

Making routing work on a non Meteor server

To enforce JavaScript routing, all requests should point to index.html. See below "rewrite" instructions for various http/proxy servers.

Apache

Create .htaccess for Apache with mod_rewrite rules:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # Always pass through requests for files that exist
  # Per http://stackoverflow.com/a/7090026/223225
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule . - [L]

  # Send all other requests to index.html where the JavaScript router can take over
  # and render the requested route
  RewriteRule ^.*$ index.html [L]
</IfModule>

Nginx

Use try_files and error_page to redirect all requests to non-existent files to index.html. Static files will be served by nginx itself.

server {
  listen 80;
  listen [::]:80;
  server_name myapp.com;

  index index.html;
  root /var/www/myapp;

  error_page 404 =200 /index.html;
  
  location / {
    try_files $uri $uri/ /index.html;
  }
}

More Repositories

1

MeteorFrontend

This is a demo package to automatically decouple the Meteor frontend part from its backend, for solo distribution.
JavaScript
54
star
2

meteor-template-var

Works as a wrapper for meteors ReactiveVar, but template instance specific.
JavaScript
40
star
3

feindura-flat-file-cms

feindura - Flat File Content Management System
PHP
38
star
4

simple-dapp-example

Simple example Ðapp built with Meteor
JavaScript
31
star
5

book-building-single-page-web-apps-with-meteor

The examples for the book "Building Single-page Web Apps with Meteor"
JavaScript
28
star
6

eth-create2-calculator

Library to calculate an ethereum create2 address in advance
JavaScript
27
star
7

meteor-template-animation-helper

A Meteor package which allows to animate/fade templates in and out
JavaScript
23
star
8

meteor-animation-helper-velocity

Animates elements inside a {{> AnimateWithVelocity}} block, by adding specific attributes to elements.
JavaScript
22
star
9

example-escrow-dapp

Simple example Ðapp using an escrow contract
JavaScript
19
star
10

meteor-animation-helper

Animates elements inside a {{> Animate}} block, by removing and adding an `animate` class.
JavaScript
18
star
11

meteor-persistent-minimongo2

Persistent Client-side Collections for Meteor using indexedDB, webSQL or localstorage
JavaScript
17
star
12

eth-deploy-crosschain

Library create a raw tx to deploy contracts at the same address on different EVM chains
JavaScript
16
star
13

bignumber.js-nolookahead

BigNumber.js version with no look ahead regex for web3.js 0.x.x
JavaScript
10
star
14

meteor-view-manager

The View manager helps to set views at specific locations in your app
JavaScript
10
star
15

randomHex

Will generate a random HEX string of a specifc byte size.
JavaScript
7
star
16

meteor-reactive-timer

Allows to run reactive functions in a given interval.
JavaScript
7
star
17

q-meteor

A tool for making and composing asynchronous promises in JavaScript -> packaged for meteor. The original repo can be found at https://github.com/kriskowal/q Documentation can be found at
JavaScript
7
star
18

MediaEmbed

CKEditor Media Embed Plugin
JavaScript
6
star
19

meteor-global-notifications

Simple global toaster notifications
JavaScript
6
star
20

ethereum-dapp-whisper-client

Ethereum's default whisper Ðapp
JavaScript
5
star
21

meteor-storage

A wrapper for localStorage, which will use chrome.storage if used in a chrome packaged app
JavaScript
5
star
22

725v2

Test interface for ERC725v2
JavaScript
5
star
23

meteor-template-session

Works like Meteor's Session, but bound to template instances.
JavaScript
4
star
24

jsGET

jsGET is a http GET-Variables clone for javascript, using the hash part of the URL (index.html#...) .
JavaScript
4
star
25

bitcoin-browser-wallet

A simple bitcoin browser wallet
CSS
4
star
26

jsMultipleSelect

A customizable fancy way to select options, even from multiple selections into one destination.
JavaScript
3
star
27

crowdsale-contracts

Crowdsale contracts
JavaScript
3
star
28

meteor-inline-form

Form elements for usage in an inline text.
JavaScript
2
star
29

iNews-Prototype

iNews news app prototype
CSS
2
star
30

MeteorMemoryTest

JavaScript
2
star
31

meteor-ifvisible.js

Meteor wrapper package for https://github.com/serkanyersen/ifvisible.js/
CoffeeScript
2
star
32

StaticScroller

A MooTools extension to position an element based on the scroll position of the window.
JavaScript
2
star
33

PlaceholderSupport

Super simple crossbrowser Placholder support fro inputs and textareas.
JavaScript
2
star
34

mycoindesk

Cryptocurrency tracking tool
HTML
1
star
35

meteorTemplateAnimationHelperDemo

A demo for the template-animation-helper package
JavaScript
1
star
36

AndroidToken

Android Tokens client
C++
1
star
37

meteor-template-store

A reactive store based on IDs for template instance specific triggers.
JavaScript
1
star
38

web3dapp-example

A simple Dapp boilerplate for the web3summit workshop
JavaScript
1
star
39

templateSessionDemo

JavaScript
1
star
40

electron-curstom-protocol-realtive-urls-repro

Test repro for https://github.com/atom/electron/issues/1747#issuecomment-174792471
JavaScript
1
star
41

feindura-Webmaster-App

iPhone app for feindura webmasters, to view multiple feindura cms statistics in one app
Objective-C
1
star
42

meteor-template-session2

The TemplateSession provides reactive variables for template instances.
JavaScript
1
star
43

meteor-ethereum-elements-demo

Demo site for the ethereum:elements and ethereum:tools meteor packages
HTML
1
star