Skip to content

Commit cdb5d18

Browse files
author
Guillaume Chau
committed
(HMR) Automatic IP detection to connect other LAN devices
1 parent 844914f commit cdb5d18

File tree

10 files changed

+52
-18
lines changed

10 files changed

+52
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center"><img src="./vue%2Bmeteor.png"></p>
22

33
<p align="center">
4-
<a href="https://meteor.com/"><img src="https://img.shields.io/badge/meteor-1.4.3.1-blue.svg"/></a>
5-
<a href="https://vuejs.org/"><img src="https://img.shields.io/badge/vue-1.x-green.svg"/> <img src="https://img.shields.io/badge/vue-2.2.4-brightgreen.svg"/></a>
4+
<a href="https://meteor.com/"><img src="https://img.shields.io/badge/meteor-1.4.4.1-blue.svg"/></a>
5+
<a href="https://vuejs.org/"><img src="https://img.shields.io/badge/vue-1.x-green.svg"/> <img src="https://img.shields.io/badge/vue-2.2.6-brightgreen.svg"/></a>
66
</p>
77

88
<br/>

packages/vue-component-dev-client/client/dev-client.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,9 @@ if (!Response.prototype.setEncoding) {
8383

8484
Meteor.startup(function () {
8585
// Dev client
86-
let port = __meteor_runtime_config__.VUE_DEV_SERVER_PORT || 3003
87-
let devUrl = __meteor_runtime_config__.VUE_DEV_SERVER_URL || null
86+
let devUrl = __meteor_runtime_config__.VUE_DEV_SERVER_URL
8887

89-
if (devUrl) {
90-
console.log('[HMR] Dev client URL', devUrl)
91-
} else {
92-
devUrl = `${Meteor.absoluteUrl().replace(new RegExp(':\\d+\\/', 'gi'), '')}:${port}`
93-
console.log('[HMR] Dev client port', port)
94-
}
88+
console.log('[HMR] Dev client URL', devUrl)
9589

9690
// NOTE: Socket lib don't allow mix HTTP and HTTPS servers URLs on client!
9791
let _socket = require('socket.io-client')(devUrl)

packages/vue-component-dev-client/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-component-dev-client',
3-
version: '0.2.8',
3+
version: '0.2.9',
44
summary: 'Hot-reloading client for vue components',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory and the files immediately inside it are automatically generated
2+
when you change this package's NPM dependencies. Commit the files in this
3+
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
4+
so that others run the same versions of sub-dependencies.
5+
6+
You should NOT check in the node_modules directory that Meteor automatically
7+
creates; if you are using git, the .gitignore file tells git to ignore it.

packages/vue-component-dev-server/.npm/package/npm-shrinkwrap.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vue-component-dev-server/package.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-component-dev-server',
3-
version: '0.0.5',
3+
version: '0.0.6',
44
summary: 'Dev server for vue hot-reloading',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md',
@@ -13,3 +13,7 @@ Package.onUse(function(api) {
1313
api.use('webapp');
1414
api.mainModule('server/main.js', 'server');
1515
});
16+
17+
Npm.depends({
18+
'local-ipv4-address': '0.0.1',
19+
})
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import localIp from 'local-ipv4-address'
2+
13
function getMeteorPort() {
24
const reg = /:\/\/.+:(\d+)/gi;
35
const result = reg.exec(Meteor.absoluteUrl());
@@ -6,12 +8,19 @@ function getMeteorPort() {
68
}
79
}
810

11+
const localIpSync = Meteor.wrapAsync(cb => {
12+
localIp().then(result => {
13+
cb(null, result)
14+
}).catch(error => {
15+
cb(error)
16+
})
17+
})
18+
919
// to define full url with port (example: https://dev.example.com:8443/)
10-
const DEVURL = process.env.HMR_URL || process.env.VUE_DEV_SERVER_URL || null;
20+
const DEVURL = process.env.HMR_URL || process.env.VUE_DEV_SERVER_URL || localIpSync();
1121

1222
// to define only dev port with same url
1323
const PORT = parseInt(process.env.HMR_PORT) || parseInt(process.env.VUE_DEV_SERVER_PORT) || getMeteorPort() || 3003;
1424

1525
// Client-side config
16-
__meteor_runtime_config__.VUE_DEV_SERVER_PORT = PORT;
17-
__meteor_runtime_config__.VUE_DEV_SERVER_URL = DEVURL;
26+
__meteor_runtime_config__.VUE_DEV_SERVER_URL = `${DEVURL}:${PORT}`;

packages/vue-component/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.8.16 - 2017-04-14
4+
5+
- Vue 2.2.6 support
6+
- Automatic IP detection for HMR to work on other devices in the local network.
7+
38
## 0.8.6 - 2017-02-21
49

510
- CSS Modules: New `<style>` attribute `module` & `$style` component property (see [PR](https://github.com/Akryum/meteor-vue-component/pull/117)). Thanks @nathantreid

packages/vue-component/package.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-component',
3-
version: '0.8.15',
3+
version: '0.8.16',
44
summary: 'VueJS single-file components that hot-reloads',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md'
@@ -43,6 +43,6 @@ Package.registerBuildPlugin({
4343
Package.onUse(function(api) {
4444
api.versionsFrom('1.4.2');
4545
api.use('isobuild:compiler-plugin@1.0.0');
46-
api.use('akryum:vue-component-dev-server@0.0.5');
47-
api.use('akryum:vue-component-dev-client@0.2.8');
46+
api.use('akryum:vue-component-dev-server@0.0.6');
47+
api.use('akryum:vue-component-dev-client@0.2.9');
4848
});

0 commit comments

Comments
 (0)