Skip to content

Enable webpack config overrides #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 11, 2018
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
13 changes: 8 additions & 5 deletions bin/elm-app-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ switch (script) {
* @return {undefined}
*/
function help(version) {
console.log('\nUsage: elm-app <command>\n');
console.log();
console.log('Usage: elm-app <command>');
console.log();
console.log('where <command> is one of:');
console.log(
' build, start, test, eject, ' + elmCommands.join(', ') + '\n'
);
console.log('\nElm ' + elmVersion + '\n');
console.log(' build, start, test, eject, ' + elmCommands.join(', '));
console.log();
console.log();
console.log('Elm ' + elmVersion);
console.log();
console.log(
'create-elm-app@' + version + ' ' + path.resolve(__dirname, '..')
);
Expand Down
6 changes: 5 additions & 1 deletion config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
const explorer = cosmiconfig('elmapp');
const result = explorer.searchSync(appDirectory);
const config = result ? result.config : loadElmJson();
const id = x => x;
const configureWebpack =
typeof config.configureWebpack === 'function' ? config.configureWebpack : id;

// WARNING:
// We support config in elm.json only for legacy reasons.
Expand Down Expand Up @@ -76,5 +79,6 @@ module.exports = {
elm: require.resolve('elm/bin/elm'),
publicUrl: getPublicUrl(config),
servedPath: getServedPath(config),
proxy: config.proxy
proxy: config.proxy,
configureWebpack
};
4 changes: 3 additions & 1 deletion scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function build(previousFileSizes) {
console.log(`Creating an optimized ${process.env.NODE_ENV} build...`);
}

const compiler = webpack(config);
const compiler = webpack(
paths.configureWebpack(config, process.env.NODE_ENV)
);
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
if (err) {
Expand Down
6 changes: 4 additions & 2 deletions scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ function performEject(pkg) {
// Update or create new package.json
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));

console.log('\nPlease wait for npm to install all required dependencies...');
console.log();
console.log('Please wait for npm to install all required dependencies...');

// Install npm packages
spawn.sync('npm', ['install'], { stdio: 'inherit' });

console.log(chalk.green('\nEjected successfully!'));
console.log();
console.log(chalk.green('Ejected successfully!'));
}

// The following dependencies will be removed:
Expand Down
7 changes: 6 additions & 1 deletion scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ choosePort(HOST, DEFAULT_PORT)
const appName = path.basename(path.dirname(paths.elmJson));
const urls = prepareUrls(protocol, HOST, port);
// Create a webpack compiler that is configured with custom messages.
const compiler = createCompiler(webpack, config, appName, urls);
const compiler = createCompiler(
webpack,
paths.configureWebpack(config, process.env.NODE_ENV),
appName,
urls
);
// Load proxy config
const proxyConfig = prepareProxy(paths.proxy, paths.appPublic);
// Serve webpack assets generated by the compiler over a web sever.
Expand Down