You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## v1.0
- Update codebase to ES6;
- Overall codebase refactoring and linting;
- __Breaking__: Remove spinner, `simple-spinner` dependency, and `-hide, --hideSpinner` command line options;
- Support for modern (ES6) and legacy (ES5) builds (legacy build is used by default);
- Support for Meteor's `<meteor-bundled-js/>` and `<meteor-bundled-css/>`;
- Support for `body.html` and `blaze-html-templates` (see updated readme);
- Support for `{{url-to-meteor-bundled-css}}` placeholder, which can be used in `<link rel="preload">`;
- __Breaking__: `--usebuild` option now accepts `<path>` to the build;
- Update NPM dependencies;
- Use `fs-extra` module to move files around;
- Check that `Meteor` and `Meteor.disconnect` exist in global space;
- If `--url` option is not passed create dummy `sockjs/info` to avoid connect DDP exceptions;
- Closing: #53, #40;
- Solving: #61, #57, #55, #42, #18;
- Taking into account: #59, #35;
Copy file name to clipboardExpand all lines: README.md
+93-65Lines changed: 93 additions & 65 deletions
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,29 @@
4
4
5
5
# Meteor Build Client
6
6
7
-
This tool builds and bundles the client part of a Meteor app with a simple index.html,
8
-
so it can be hosted on any server or even loaded via the `file://` protocol.
7
+
This tool builds and bundles the client part of a Meteor app with a simple `index.html`, so it can be hosted on any server or even loaded via the `file://` protocol.
9
8
10
9
## Installation
11
10
12
-
$ [sudo] npm install -g meteor-build-client
11
+
```shell
12
+
npm install -g meteor-build-client
13
+
```
13
14
14
15
## Usage
15
16
16
-
// cd into your meteor app
17
-
$ cd myApp
17
+
```shell
18
+
// cd into your meteor app
19
+
cd /my/app
20
+
21
+
// run meteor-build-client
22
+
meteor-build-client ../output/directory
23
+
```
18
24
19
-
// run meteor-build-client
20
-
$ meteor-build-client ../myOutputFolder
25
+
## Important notes:
21
26
22
-
**Warning** the content of the output folder will be deleted before building the new output! So dont do things like
23
-
`$ meteor-build-client /home`!
27
+
-__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`!
28
+
-__Do not use dynamic imports!__ e.g. `import('/eager/file');`;
29
+
- By default this package link __legacy__ ES5 bundle build.
24
30
25
31
### Output
26
32
@@ -33,117 +39,139 @@ The content of the output folder could look as follows:
33
39
34
40
For a list of options see:
35
41
36
-
$ meteor-build-client --help
42
+
```shell
43
+
meteor-build-client --help
44
+
```
37
45
38
46
### Passing a settings.json
39
47
40
48
You can pass an additional settings file using the `--settings` or `-s` option:
If this option was not set, it will set the server to `""` (empty string) and will add a `Meteor.disconnect()` after Meteor was loaded.
64
+
If you pass `"default"`, your app will try to connect to the server where the application was served from. If this option was not set, it will set the server to `""` (empty string) and will add a `Meteor.disconnect()` after Meteor was loaded.
56
65
57
66
### Absolute or relative paths
58
67
59
-
If you want to be able to start you app by simply opening the index.html (using the `file://` protocol),
60
-
you need to link your files relative. You can do this by setting the `--path` or `-p` option:
68
+
If you want to be able to start you app by simply opening the index.html (using the `file://` protocol), you need to link your files relative. You can do this by setting the `--path` or `-p` option:
61
69
62
-
$ meteor-build-client ../myOutputFolder -p ""
70
+
```shell
71
+
meteor-build-client ../output/directory -p ""
72
+
```
63
73
64
74
The default path value is `"/"`.
65
75
66
76
*Note* When set a path value, it will also replace this path in you Meteor CSS file, so that fonts etc link correctly.
67
77
68
-
69
78
### Using your own build folder
70
79
71
-
If you want to use your own build folder by running `meteor build`yourself, specify the `--usebuild` flag and meteor-build-client will not run the meteor build command for you. It will expect that the build folder be located up a directory from the app folder (A sibling to /app, Meteor's default location).
80
+
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.
72
81
73
-
### Using custom templates
82
+
### Recommended packages for client-only build
74
83
75
-
If you want to provide a custom template for the initial HTML provide an HTML file with the `--template` or `-t` option:
84
+
If you're building server-less standalone web application we recommend to replace `meteor-base`with `meteor` and `webapp` packages.
The template file need to contain the following placholders: `{{> head}}`, `{{> css}}` and `{{> scripts}}`.
80
-
The following example adds a simple loading text to the initial HTML file (Your app should later take care of removing the loading text):
93
+
### Template
94
+
95
+
Following Meteor's recommended usage of `<meteor-bundled-css />` and `<meteor-bundled-js/>` this tags will be replaced with links to generated CSS and JS files respectively. Optionally, use `{{url-to-meteor-bundled-css}}` as a placeholder for URL to generated CSS file. We encourage to use `static-html` (*for non-Blaze projects*) or `blaze-html-templates` (*for Blaze projects*) package for creating bare HTML template in your app, minimal example:
96
+
97
+
```html
98
+
<!-- client/head.html -->
99
+
<head>
100
+
<metacharset="UTF-8">
101
+
<!-- recommended "fragment" to mark as JS-powered website for search engines -->
102
+
<metaname="fragment"content="!">
103
+
104
+
<title>My Meteor App</title>
105
+
106
+
<!-- recommended "preload" for CSS bundle file -->
Where `<meteor-bundled-css />` will be replaced with `<link />` element to generated CSS file(s) and `{{url-to-meteor-bundled-css}}` will be replaced with URL to generated CSS file.
By linking a file from your `public` folder (e.g. `loadingScreen.css`) and moving the `{{> css}}` and `{{> scripts}}` placeholder to the end of the `<body>` tag,
98
-
you can simply style your loading screen.
99
-
Because the small CSS file (`loadingScreen.css`) and the body content will be loaded *before* the Meteor app script, the the user sees the nice Loading text.
120
+
121
+
Where `<meteor-bundled-js />` will be replaced with `<script />` element(s) to generated JS file(s).
100
122
101
123
## Connecting to a Meteor server
102
124
103
125
In order to connect to a Meteor servers, create DDP connection by using `DDP.connect()`, as seen in the following example:
104
126
105
127
```js
106
128
// This Should be in both server and client in a lib folder
// set the new DDP connection to all internal packages, which require one
114
-
Meteor.connection= DDPConnection;
115
-
Accounts.connection=Meteor.connection;
116
-
Meteor.users=newMongo.Collection('users');
117
-
Meteor.connection.subscribe('users');
135
+
// set the new DDP connection to all internal packages, which require one
136
+
Meteor.connection= DDPConnection;
137
+
Accounts.connection=Meteor.connection;
138
+
Meteor.users=newMongo.Collection('users');
139
+
Meteor.connection.subscribe('users');
118
140
119
-
// And then you subscribe like this:
120
-
DDPConnection.subscribe("mySubscription");
141
+
// And then you subscribe like this:
142
+
DDPConnection.subscribe('mySubscription');
121
143
}
122
144
```
123
145
124
146
## Making routing work on a non Meteor server
125
147
126
-
To be able to open URLs and let them be handled by the client side JavaScript, you need to rewrite URLs on the server side, so they point always to your index.html.
148
+
To be able to open URLs and let them be handled by the client side JavaScript, you need to rewrite URLs on the server side, so they point always to `index.html`
149
+
150
+
### Apache
127
151
128
152
For apache a `.htaccess` with `mod_rewrite` could look as follow:
153
+
129
154
```bash
130
155
<IfModule mod_rewrite.c>
131
-
RewriteEngine On
132
-
RewriteBase /
133
-
134
-
# Always pass through requests for files that exist
135
-
# Per http://stackoverflow.com/a/7090026/223225
136
-
RewriteCond %{REQUEST_FILENAME} -f [OR]
137
-
RewriteCond %{REQUEST_FILENAME} -d
138
-
RewriteRule . - [L]
139
-
140
-
# Send all other requests to index.html where the JavaScript router can take over
141
-
# and render the requested route
142
-
RewriteRule ^.*$ index.html [L]
156
+
RewriteEngine On
157
+
RewriteBase /
158
+
159
+
# Always pass through requests for files that exist
160
+
# Per http://stackoverflow.com/a/7090026/223225
161
+
RewriteCond %{REQUEST_FILENAME} -f [OR]
162
+
RewriteCond %{REQUEST_FILENAME} -d
163
+
RewriteRule . - [L]
164
+
165
+
# Send all other requests to index.html where the JavaScript router can take over
166
+
# and render the requested route
167
+
RewriteRule ^.*$ index.html [L]
143
168
</IfModule>
144
169
```
145
170
146
-
For nginx:
171
+
### nginx:
172
+
173
+
Use `try_files` and `error_page` to redirect all requests to non-existent files to `index.html`
0 commit comments