Skip to content
Merged
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
30 changes: 22 additions & 8 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ const fs = require('fs');
const path = require('path');
const yargs = require('yargs');
const { hideBin } = require('yargs/helpers');
const localConfigExists = fs.existsSync(
path.join(__dirname, './webpack.local-config.js')
);

const argv = yargs(hideBin(process.argv))
.command('* [profile]', 'Open Firefox Profiler, on [profile] if included.')
.option('c', {
alias: 'config',
describe: 'Path to local webpack config',
type: 'string',
})
// Disabled --version flag since no version number in package.json.
.version(false)
.strict()
Expand Down Expand Up @@ -73,15 +75,27 @@ const serverConfig = {
};

// Allow a local file to override various options.
if (localConfigExists) {
let localConfigFile; // Set by readConfig() below.
const defaultLocalConfigPath = path.join(
__dirname,
'./webpack.local-config.js'
);
const readConfig = (localConfigPath) => {
const configRequirePath = `./${path.relative(__dirname, localConfigPath)}`;
try {
require('./webpack.local-config.js')(config, serverConfig);
require(configRequirePath)(config, serverConfig);
localConfigFile = path.basename(configRequirePath);
} catch (error) {
console.error(
'Unable to load and apply settings from webpack.local-config.js'
`Unable to load and apply settings from ${configRequirePath}`
);
console.error(error);
}
};
if (argv.config) {
readConfig(argv.config);
} else if (fs.existsSync(defaultLocalConfigPath)) {
readConfig(defaultLocalConfigPath);
}

const profilerUrl = `http://${host}:${port}`;
Expand Down Expand Up @@ -142,9 +156,9 @@ server
'> You can change this default port with the environment variable FX_PROFILER_PORT.\n'
);
}
if (localConfigExists) {
if (localConfigFile) {
console.log(
'> We used your local file "webpack.local-config.js" to mutate webpack’s config values.'
`> We used your local file "${localConfigFile}" to mutate webpack’s config values.`
);
} else {
console.log(stripIndent`
Expand Down