Skip to content

Commit

Permalink
refactor(serve): added support devices
Browse files Browse the repository at this point in the history
  • Loading branch information
kotarella1110 committed May 14, 2019
1 parent 0719a98 commit f6b377e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = {
- [x] Bundle with webpack before preparing.
- [x] Live Reload (Hot Module Replacement) with webpack-dev-server.
- [x] Emulator
- [ ] Device
- [x] Device

## License

Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"homepage": "https://github.com/kotarella1110/cordova-plugin-webpack#readme",
"dependencies": {
"@types/elementtree": "^0.1.0",
"@types/ip": "^1.1.0",
"@types/node": "^12.0.0",
"@types/react-dev-utils": "^9.0.1",
"@types/webpack": "^4.4.31",
Expand All @@ -47,6 +48,7 @@
"elementtree": "^0.1.7",
"express": "^4.16.4",
"glob": "^7.1.4",
"ip": "^1.1.5",
"react-dev-utils": "^9.0.1",
"source-map-support": "^0.5.12",
"webpack": "^4.31.0",
Expand Down
9 changes: 8 additions & 1 deletion src/webpackServe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'source-map-support/register';
import * as path from 'path';
import * as fs from 'fs';
import * as glob from 'glob';
import * as ip from 'ip';
import webpack from 'webpack';
import WebpackInjectPlugin from 'webpack-inject-plugin';
import WebpackDevServer from 'webpack-dev-server';
Expand All @@ -24,6 +25,10 @@ module.exports = (ctx: any) =>
try {
const defaultHost = '0.0.0.0';
const defaultPort = 8080;
const defaultAccessHosts = {
android: '10.0.2.2',
ios: 'localhost',
};

const port = await choosePort(defaultHost, defaultPort);
if (!port) {
Expand All @@ -44,7 +49,9 @@ module.exports = (ctx: any) =>
const configXml = new CordovaConfigParser(configXmlPath);
configXml.setContent(
`http://${
platform === 'android' ? '10.0.2.2' : 'localhost'
platform === 'android'
? ip.address() || defaultAccessHosts.android
: ip.address() || defaultAccessHosts.ios
}:${port}`,
);
if (platform === 'ios')
Expand Down

0 comments on commit f6b377e

Please sign in to comment.