From 695801ec1035fc458eef8eaf3284d8d00fbb7f63 Mon Sep 17 00:00:00 2001 From: Saulo Vallory Date: Fri, 28 Jul 2017 00:27:48 -0300 Subject: [PATCH 1/2] Allow partially overriding webpack config If a webpack.config.js file is found in the project root, it's loaded after all other configs so configuration can be overriden. --- packages/@angular/cli/models/webpack-config.ts | 5 ++++- .../cli/models/webpack-configs/custom.ts | 16 ++++++++++++++++ .../@angular/cli/models/webpack-configs/index.ts | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 packages/@angular/cli/models/webpack-configs/custom.ts diff --git a/packages/@angular/cli/models/webpack-config.ts b/packages/@angular/cli/models/webpack-config.ts index e12daf8842b9..c44b1419925f 100644 --- a/packages/@angular/cli/models/webpack-config.ts +++ b/packages/@angular/cli/models/webpack-config.ts @@ -8,7 +8,8 @@ import { getProdConfig, getStylesConfig, getNonAotConfig, - getAotConfig + getAotConfig, + getCustomConfig } from './webpack-configs'; const path = require('path'); @@ -51,6 +52,8 @@ export class NgCliWebpackConfig { webpackConfigs.push(typescriptConfigPartial); } + webpackConfigs.push(getCustomConfig(this.wco)); + this.config = webpackMerge(webpackConfigs); return this.config; } diff --git a/packages/@angular/cli/models/webpack-configs/custom.ts b/packages/@angular/cli/models/webpack-configs/custom.ts new file mode 100644 index 000000000000..695b7272f7d7 --- /dev/null +++ b/packages/@angular/cli/models/webpack-configs/custom.ts @@ -0,0 +1,16 @@ +import * as fs from 'fs'; +import * as path from 'path'; + +import { WebpackConfigOptions } from '../webpack-config'; + +export const getCustomConfig = function (_wco: WebpackConfigOptions) { + const customConfigPath = path.join(_wco.projectRoot, 'webpack.config.js'); + + console.log('checking for webpack custom config in', customConfigPath); + if (fs.statSync(customConfigPath)) { + console.log('Found! Loading...'); + return require(customConfigPath); + } + + return {}; +}; diff --git a/packages/@angular/cli/models/webpack-configs/index.ts b/packages/@angular/cli/models/webpack-configs/index.ts index 7c985a1e093d..b7f42bb234df 100644 --- a/packages/@angular/cli/models/webpack-configs/index.ts +++ b/packages/@angular/cli/models/webpack-configs/index.ts @@ -1,5 +1,6 @@ export * from './browser'; export * from './common'; +export * from './custom'; export * from './development'; export * from './production'; export * from './styles'; From 88bd0fd59d806b80b0a2bf2baa61f711496e5f84 Mon Sep 17 00:00:00 2001 From: Saulo Vallory Date: Fri, 28 Jul 2017 01:54:54 -0300 Subject: [PATCH 2/2] Remove console.log calls and fix file check --- packages/@angular/cli/models/webpack-configs/custom.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/@angular/cli/models/webpack-configs/custom.ts b/packages/@angular/cli/models/webpack-configs/custom.ts index 695b7272f7d7..9b4a3797d681 100644 --- a/packages/@angular/cli/models/webpack-configs/custom.ts +++ b/packages/@angular/cli/models/webpack-configs/custom.ts @@ -6,9 +6,7 @@ import { WebpackConfigOptions } from '../webpack-config'; export const getCustomConfig = function (_wco: WebpackConfigOptions) { const customConfigPath = path.join(_wco.projectRoot, 'webpack.config.js'); - console.log('checking for webpack custom config in', customConfigPath); - if (fs.statSync(customConfigPath)) { - console.log('Found! Loading...'); + if (fs.existsSync(customConfigPath)) { return require(customConfigPath); }