Skip to content

Commit 5b21dac

Browse files
committed
Handle server args and log config details on start
1 parent b5848b9 commit 5b21dac

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

server.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ const defaults = {
2929
};
3030

3131
export default {
32-
// Development (watch files and auto inject/reload on change)
32+
// Development (preview, local URLs, watch enabled)
3333
dev: {
3434
...defaults,
3535
files: ['CHANGELOG.md', 'docs/**/*', 'lib/**/*'],
3636
port: 3000,
3737
open: true,
3838
snippet: true,
3939
},
40-
// Production (watch disabled)
40+
// Production (index, CDN URLs, watch disabled)
4141
prod: {
4242
...defaults,
4343
port: 8080,
@@ -46,7 +46,7 @@ export default {
4646
index: 'index.html',
4747
},
4848
},
49-
// Test: (watch disabled, blank page route, unique port)
49+
// Test (preview, local URLs, watch disabled)
5050
test: {
5151
...defaults,
5252
middleware: [

server.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { create } from 'browser-sync';
2-
import config from './server.config.js';
2+
import serverConfigs from './server.config.js';
33

44
const bsServer = create();
5-
const isDev = process.argv.includes('--dev');
6-
const settings = config[isDev ? 'dev' : 'prod'];
5+
const args = process.argv.slice(2);
6+
const configName =
7+
Object.keys(serverConfigs).find(name => args.includes(`--${name}`)) || 'prod';
8+
const settings = serverConfigs[configName];
79

8-
console.log(
9-
[
10-
'\n',
11-
'Starting',
12-
isDev ? 'development' : 'standard',
13-
'server',
14-
`(watch: ${isDev})`,
15-
'\n',
16-
].join(' ')
17-
);
10+
// prettier-ignore
11+
console.log(`\nStarting ${configName} server (${settings.server.index}, watch: ${Boolean(settings.files)})\n`);
1812

1913
bsServer.init(settings);

0 commit comments

Comments
 (0)