Skip to content

Commit 8ae624d

Browse files
committed
Merged release/1.0.0-beta into master
2 parents 7efe97e + c75eb52 commit 8ae624d

File tree

14 files changed

+721
-446
lines changed

14 files changed

+721
-446
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"typescript.tsdk": "./node_modules/typescript/lib"
3-
}
3+
}

README.md

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,36 @@
11
## HTTP Dev-Server with Hot-Reload for JavaScript (ES6 Modules)
22

3-
#### This library consist of:
4-
#### - Express HTTP Server enhanced with WebSocket emitter on file changes
5-
#### - SystemJS - ES6 Module Loader
6-
#### - WebSocket receiver for browser that trigger Hot-Reload for changed ES6 Modules
3+
#### Express Server ehnanced with Chokidar WebSocket Server emitting events on file changes
74

85
- Npm package: https://www.npmjs.com/package/jspm-hmr
96
- ReactJS Boilerplate using this dev-server - https://github.com/piotrwitek/react-redux-typescript-starter-kit
107

118
---
129

1310
### Features
14-
- Quickly Bootstrap new Babel or TypeScript App using nice CLI Wizard - include Dev Server with Hot-Reload using SystemJS & JSPM
15-
- Fast & Scalable Hot-Reload Capabilities (perfect for ReactJS, Angular2, Vue & more...)
16-
- Live-reload static resources like styles (CSS, SCSS), images, fonts or HTML templates through [SystemJS Plugins Ecosystem](https://github.com/systemjs/systemjs#plugins)
17-
- Leveraging [SystemJS](https://github.com/systemjs/systemjs) for Universal Module Loading Support
11+
- Fast Hot-Reload - using [systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader)
12+
- Live-reload static files (e.g. styles (CSS/SCSS), images, fonts or HTML templates) through [SystemJS Plugins Ecosystem](https://github.com/systemjs/systemjs#plugins)
13+
- Universal Module Loading with [SystemJS](https://github.com/systemjs/systemjs)
14+
- Initialize minimal App with Babel or TypeScript transpilation workflow using CLI Wizard (including Hot-Reload configuration)
1815

1916
---
2017

2118
### Quick Start
22-
Includes:
23-
- Bootstrap Minimal App Boilerplate with fancy CLI Wizard
24-
- Transpilation workflow setup to choose: Babel or TypeScript
19+
- Bootstrap Minimal App Boilerplate guided by CLI Wizard
20+
- Transpilation workflow setup: choose Babel or TypeScript
2521

2622
> __Tip:__ Confirm all Wizard Questions with Enter for default __Babel__ setup
2723
28-
##### _ONE-LINE-COMMAND_
24+
##### _ONE-LINER_
2925
```
3026
npm i jspm@beta jspm-hmr -D && ./node_modules/.bin/jspm init && ./node_modules/.bin/jspm i systemjs-hot-reloader && ./node_modules/.bin/jspm-hmr -I && npm start
3127
```
3228

33-
Now you can open `app.js` or `es6module.js` file, make some changes and save it to see __Hot-Reload__ update running application without page refresh!
29+
Now open `app.js` or `es6module.js` file from `src`, make some changes and save to see __Hot-Reload__ updates in running application without page reload!
3430

3531
---
3632

37-
### Project setup
33+
### Project prerequisite
3834

3935
- http://jspm.io - package manager and bundler for JS apps (webpack alternative)
4036
`npm i jspm@beta -D`
@@ -49,7 +45,7 @@ Now you can open `app.js` or `es6module.js` file, make some changes and save it
4945
$ npm i jspm-hmr -D
5046
```
5147

52-
> __Tip:__ You can install it globally using -g flag so you can use it as simple http server in any directory on your machine
48+
> __Tip:__ You can install this module globally using -g flag and use it as a simple static http server in any folder on your machine
5349
5450
> __Pro-Tip:__ You can use --init flag to initialize your project with index.html, app.js, server.js files - configured with hot-module-reload out-of-the-box
5551
@@ -61,50 +57,55 @@ $ jspm-hmr [path] [options]
6157
```
6258
Options:
6359

64-
-h, --help output usage information
65-
-V, --version output the version number
66-
-i, --init CLI Wizard to bootstrap your project
67-
-o, --open automatically open browser (default: false)
68-
-p, --port <number> port number (default: 8888)
69-
-c, --cache <seconds> enable Cache-Control with max-age=<seconds> (default: -1)
70-
-P, --proxy <url> proxies requests to specified url
71-
-S, --ssl enables https (by default uses built-in self-signed cert)
72-
-K, --key <path> path to ssl-key .pem file (overrides default key)
73-
-C, --cert <path> path to ssl-cert .pem file (overrides default cert)
60+
-h, --help output usage information
61+
-V, --version output the version number
62+
-i, --init CLI Wizard to bootstrap your project
63+
-o, --open automatically open browser (default: false)
64+
-p, --port <number> port number (default: 3000)
65+
-a, --address <address> custom address (default: localhost)
66+
-c, --cache <seconds> enable Cache-Control with max-age=<seconds> (default: -1)
67+
-P, --proxy <address>:<port> proxies requests to specified target
68+
--proxy-route <route_path> proxies only requests that match route path (default: *)
69+
-S, --ssl enables https (by default uses built-in self-signed cert)
70+
-K, --key <path> path to ssl-key .pem file (overrides default key)
71+
-C, --cert <path> path to ssl-cert .pem file (overrides default cert)
72+
-F, --fallback <rewrite_target> enable HTML5 History Api Fallback (/index.html)
73+
--verbose more logging messages for: fallback
74+
--disable-hmr disable Hot-Reload (Chokidar Socket Server)
7475
---
7576

7677
### Examples:
7778

78-
- Start dev server in PWD on port "4444" & automatically open in browser (last active window takes precedence)
79+
- Start dev server in `pwd` on port "4444" & automatically open in browser (last active window takes precedence)
7980
```
8081
$ jspm-hmr . --port 4444 --open
8182
```
8283

83-
- Start dev server in directory "dist" with caching set to "3600 sec" and proxy target set to "http://localhost:1234"
84+
- Start dev server in directory "dist" with caching set to "3600 sec" and proxy target set to "http://localhost:1234" with proxy route pattern equal to `/api/`
8485
```
85-
$ jspm-hmr dist --cache 3600 --proxy http://localhost:1234
86+
$ jspm-hmr dist --cache 3600 --proxy http://localhost:1234 --proxy-route /api/
8687
```
8788

8889
- Start dev server in directory "dist" with https using built-in self-signed cert
8990
```
9091
$ jspm-hmr dist --ssl
9192
```
9293

94+
- Start dev server in `pwd` with HTML5 History Api Fallback
95+
```
96+
$ jspm-hmr --fallback
97+
```
98+
9399
---
94100

95101
### How it works
96-
Watches specified files for changes in chosen path and emits events through web sockets on changes to your client to reload that particular JavaScript modules that has changed.
97-
`-i` or `--init` flag will run CLI Wizard to bootstrap your `index.html`, `app.js` and `server.js` in your project folder with Dev Server and Hot-Reload configuration for quick start.
98-
99-
It uses great [systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader) for Client and [chokidar-socket-emitter](https://github.com/capaj/chokidar-socket-emitter) for Dev Server.
100-
101-
---
102+
Chokidar process on dev server watches specified path for file changes and emits events through web socket to the browser web socket client to reload that particular JavaScript module that has been changed.
102103

103-
### Dependencies:
104-
- [http-server](https://github.com/indexzero/http-server)
105-
- [chokidar-socket-emitter](https://github.com/capaj/chokidar-socket-emitter)
104+
Uses:
105+
- [systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader) for WebSocket Client
106+
- [chokidar-socket-emitter](https://github.com/capaj/chokidar-socket-emitter) for WebSocket Server
106107

107-
### Peer Dependencies:
108+
### Mandatory Peer Dependencies:
108109
- [jspm](https://github.com/jspm/jspm-cli)
109110
- [systemjs-hot-reloader](https://github.com/capaj/systemjs-hot-reloader)
110111

boilerplate/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
<head>
55
<meta charset="utf-8">
6-
<meta name="description" content="">
6+
<meta name="description" content>
77
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
88
<title>jspm-hmr</title>
9-
<link rel="stylesheet" href="assets/loader-style.css">
9+
<link href="assets/loader-style.css" rel="stylesheet">
1010
</head>
1111

1212
<body>
@@ -31,7 +31,7 @@
3131
<script type="text/javascript">
3232
SystemJS.import('systemjs-hot-reloader').then(function(HotReloader) {
3333
// if you're running server on custom port please remember to update below
34-
new HotReloader.default('http://localhost:8888');
34+
new HotReloader.default('http://localhost:3000');
3535
});
3636
// load main module of your app with SystemJS
3737
SystemJS.trace = true;
@@ -40,4 +40,4 @@
4040
<!-- loading-app:end -->
4141
</body>
4242

43-
</html>
43+
</html>

boilerplate/server.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
'use strict';
22
const jspmHmrServer = require('jspm-hmr');
3+
34
const options = {
4-
open: true
5+
fallback: '/index.html',
56
};
67

7-
jspmHmrServer.start(options);
8+
// SERVER
9+
const server = jspmHmrServer.createServer(options);
10+
11+
server
12+
.listen(3000, (err) => {
13+
console.log('[debug] %j', server.address());
14+
console.log('\n>>> hit CTRL-C twice to exit <<<\n');
15+
})
16+
.on('error', function (err) {
17+
if (err.code === 'EADDRINUSE') {
18+
console.log(`\n[WARNING] Selected address is in use: ${URL}`);
19+
console.log(`[WARNING] Please try again using different port or address...\n`);
20+
21+
process.exit();
22+
}
23+
});

package.json

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jspm-hmr",
3-
"version": "0.7.1",
3+
"version": "1.0.0-0",
44
"description": "HOT-RELOAD & DEV-SERVER for Vanilla JavaScript (ES6 Modules) - powered by SystemJS & JSPM",
55
"author": "Piotr Witek <[email protected]> (http://piotrwitek.github.io)",
66
"repository": "https://github.com/piotrwitek/jspm-hmr",
@@ -17,35 +17,41 @@
1717
"node": ">=4"
1818
},
1919
"scripts": {
20-
"precommit": "npm run lint",
21-
"prepush": "npm run check & npm test",
20+
"precommit": "yarn run lint",
21+
"prepush": "yarn run check & yarn test",
2222
"prepublishOnly": "yarn run reinstall && yarn run check && yarn run test && yarn run build",
23-
"reinstall": "shx rm -rf node_modules/ && yarn install",
23+
"clean": "shx rm -rf node_modules/",
24+
"reinstall": "yarn run clean && yarn install",
2425
"build:es5": "shx rm -rf es5 && tsc -p src --outDir es5",
2526
"build:es6": "shx rm -rf es6 && tsc -p src --outDir es6 -t 'ES2015'",
2627
"build": "yarn run build:es5 & yarn run build:es6",
2728
"check": "yarn run lint & yarn run tsc",
2829
"lint": "tslint --project src/tsconfig.json",
2930
"tsc": "tsc -p src --noEmit",
3031
"test": "echo 'No tests yet!'",
31-
"dev": "ts-node -P lib lib/cli.ts"
32+
"dev": "ts-node -P src src/cli.ts boilerplate"
3233
},
3334
"dependencies": {
34-
"chokidar-socket-emitter": "^0.5.2",
35+
"chokidar-socket-emitter": "^0.6.0",
3536
"commander": "^2.9.0",
36-
"http-server": "^0.9.0",
37+
"compression": "^1.6.2",
38+
"connect-history-api-fallback": "^1.3.0",
39+
"express": "^4.14.1",
40+
"http-proxy": "^1.16.2",
3741
"opener": "^1.4.1",
3842
"shelljs": "^0.7.6",
3943
"tslib": "^1.5.0"
4044
},
4145
"devDependencies": {
42-
"@types/node": "^7.0.0",
43-
"@types/shelljs": "^0.3.32",
44-
"husky": "^0.12.0",
46+
"@types/compression": "^0.0.33",
47+
"@types/express": "^4.0.35",
48+
"@types/node": "^7.0.5",
49+
"@types/shelljs": "^0.6.0",
50+
"husky": "^0.13.1",
4551
"shx": "^0.2.2",
46-
"ts-node": "^2.0.0",
47-
"tslint": "^4.3.1",
48-
"typescript": "^2.1.5"
52+
"ts-node": "^2.1.0",
53+
"tslint": "^4.4.2",
54+
"typescript": "^2.1.6"
4955
},
5056
"peerDependencies": {
5157
"jspm": ">=0.17.0-beta.20"

0 commit comments

Comments
 (0)