Skip to content

Commit 5a284ea

Browse files
authored
Merge pull request #85 from BeAPI/feature/multiple-bs-instances
Feature/multiple bs instances
2 parents 354b291 + 99a5ba3 commit 5a284ea

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ dist/
7373
src/conf-img/*.csv
7474

7575
### yarn
76-
yarn.lock
76+
yarn.lock
77+
78+
### config
79+
.port
80+
.bs-port

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/BeAPI/beapi-frontend-framework"
88
},
99
"scripts": {
10-
"start": "node_modules/.bin/concurrently -k -n \"Webpack,PHP Server\" -p \"[{name}]\" -c \"green, blue\" \"node_modules/.bin/webpack --mode=development --watch\" \"php -S localhost:9090\"",
10+
"start": "node_modules/.bin/concurrently -k -n \"Webpack,PHP Server\" -p \"[{name}]\" -c \"green, blue\" \"node_modules/.bin/webpack --mode=development --watch\" \"sh server.sh\"",
1111
"build:dev": "node_modules/.bin/webpack --mode=development && npm run icon && npm run favicon",
1212
"build:prod": "npm run clean && node_modules/.bin/webpack --mode=production && npm run icon && npm run favicon",
1313
"build": "npm run clean && node_modules/.bin/webpack --mode=production && npm run build:dev",

server.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
PORT=9090
3+
BSPORT=3000
4+
5+
while [ -n "$(lsof -Pi :${PORT} -sTCP:LISTEN -t)" ]; do
6+
((PORT++))
7+
done
8+
9+
while [ -n "$(lsof -Pi :${BSPORT} -sTCP:LISTEN -t)" ]; do
10+
((BSPORT += 2))
11+
done
12+
13+
echo "BS will run on port ${BSPORT}"
14+
15+
echo $PORT > ".port"
16+
echo $BSPORT > ".bs-port"
17+
18+
echo "Server is running on port ${PORT} and BrowserSync on port ${BSPORT}"
19+
php -S localhost:${PORT}

webpack.config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const config = require('./webpack.settings')
23
const path = require('path')
34
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
@@ -10,7 +11,15 @@ const PhpOutputPlugin = require('./src/js/vendor/webpack-php-output')
1011
const SoundsPlugin = require('sounds-webpack-plugin')
1112
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
1213
const WebpackProgressOraPlugin = require('webpack-progress-ora-plugin')
14+
const getServerPort = function(portFile) {
15+
try {
16+
require('fs').accessSync(portFile, fs.R_OK | fs.W_OK)
1317

18+
return parseInt(fs.readFileSync(portFile, 'utf8'))
19+
} catch (e) {
20+
return false
21+
}
22+
}
1423
const webpackConfig = {
1524
entry: config.entry,
1625
output: {
@@ -179,7 +188,8 @@ module.exports = (env, argv) => {
179188
}),
180189
new BrowserSyncPlugin(
181190
{
182-
proxy: 'http://[::1]:' + config.port,
191+
port: getServerPort('./.bs-port') || 3000,
192+
proxy: 'http://[::1]:' + (getServerPort('./.port') || 9090),
183193
files: [
184194
{
185195
match: config.refresh,

webpack.settings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module.exports = {
66
'editor-style': './src/scss/editor-style.scss',
77
},
88
assetsPath: path.resolve(__dirname, 'dist/assets'),
9-
port: 9090,
109
dev: process.env.NODE_ENV === 'dev',
1110
refresh: [
1211
'dist/**/*.php',

0 commit comments

Comments
 (0)