Skip to content

Commit aa4eb08

Browse files
committed
feat (webpack) : add dynamic ports from port files
1 parent 6cc3bc1 commit aa4eb08

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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 BrowserSyncPlugin = require('browser-sync-webpack-plugin')
34
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
@@ -8,7 +9,15 @@ const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
89
const SoundsPlugin = require('sounds-webpack-plugin')
910
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
1011
const WebpackProgressOraPlugin = require('webpack-progress-ora-plugin')
12+
const getServerPort = function(portFile, defaultPort) {
13+
try {
14+
require('fs').accessSync(portFile, fs.R_OK | fs.W_OK)
1115

16+
return parseInt(fs.readFileSync(portFile, 'utf8'))
17+
} catch (e) {
18+
return defaultPort
19+
}
20+
}
1221
const webpackConfig = {
1322
entry: config.entry,
1423
output: {
@@ -168,7 +177,8 @@ module.exports = (env, argv) => {
168177
}),
169178
new BrowserSyncPlugin(
170179
{
171-
proxy: 'http://[::1]:' + config.port,
180+
port: getServerPort('./.bs-port', 3000),
181+
proxy: 'http://[::1]:' + getServerPort('./.port', 9090),
172182
files: [
173183
{
174184
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)