Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ dist/
src/conf-img/*.csv

### yarn
yarn.lock
yarn.lock

### config
.port
.bs-port
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/BeAPI/beapi-frontend-framework"
},
"scripts": {
"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\"",
"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\"",
"build:dev": "node_modules/.bin/webpack --mode=development && npm run icon && npm run favicon",
"build:prod": "npm run clean && node_modules/.bin/webpack --mode=production && npm run icon && npm run favicon",
"build": "npm run clean && node_modules/.bin/webpack --mode=production && npm run build:dev",
Expand Down
19 changes: 19 additions & 0 deletions server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
PORT=9090
BSPORT=3000

while [ -n "$(lsof -Pi :${PORT} -sTCP:LISTEN -t)" ]; do
((PORT++))
done

while [ -n "$(lsof -Pi :${BSPORT} -sTCP:LISTEN -t)" ]; do
((BSPORT += 2))
done

echo "BS will run on port ${BSPORT}"

echo $PORT > ".port"
echo $BSPORT > ".bs-port"

echo "Server is running on port ${PORT} and BrowserSync on port ${BSPORT}"
php -S localhost:${PORT}
12 changes: 11 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs')
const config = require('./webpack.settings')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
Expand All @@ -8,7 +9,15 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const SoundsPlugin = require('sounds-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const WebpackProgressOraPlugin = require('webpack-progress-ora-plugin')
const getServerPort = function(portFile) {
try {
require('fs').accessSync(portFile, fs.R_OK | fs.W_OK)

return parseInt(fs.readFileSync(portFile, 'utf8'))
} catch (e) {
return false
}
}
const webpackConfig = {
entry: config.entry,
output: {
Expand Down Expand Up @@ -168,7 +177,8 @@ module.exports = (env, argv) => {
}),
new BrowserSyncPlugin(
{
proxy: 'http://[::1]:' + config.port,
port: getServerPort('./.bs-port') || 3000,
proxy: 'http://[::1]:' + (getServerPort('./.port') || 9090),
files: [
{
match: config.refresh,
Expand Down
1 change: 0 additions & 1 deletion webpack.settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module.exports = {
'editor-style': './src/scss/editor-style.scss',
},
assetsPath: path.resolve(__dirname, 'dist/assets'),
port: 9090,
dev: process.env.NODE_ENV === 'dev',
refresh: [
'dist/**/*.php',
Expand Down