From bfed1ebc9532cbca151d90b71c62e8011c4a6309 Mon Sep 17 00:00:00 2001 From: Eloy Toro Date: Tue, 5 Apr 2016 23:41:44 -0430 Subject: [PATCH] making it so it requires all the webpack config --- dist/server/index.js | 30 +++++++++++++++++++----------- src/server/index.js | 31 +++++++++++++++++++------------ 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/dist/server/index.js b/dist/server/index.js index fe3c80a863d2..5c488af0c42b 100755 --- a/dist/server/index.js +++ b/dist/server/index.js @@ -1,6 +1,14 @@ #!/usr/bin/env node 'use strict'; +var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); + +var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); + +var _extends2 = require('babel-runtime/helpers/extends'); + +var _extends3 = _interopRequireDefault(_extends2); + var _webpack = require('webpack'); var _webpack2 = _interopRequireDefault(_webpack); @@ -99,23 +107,23 @@ _webpack4.default.entry.preview.push(storybookConfigPath); // load custom webpack configurations var customConfigPath = _path2.default.resolve(configDirPath, 'webpack.config.js'); +var finalConfig = _webpack4.default; if (_fs2.default.existsSync(customConfigPath)) { var customConfig = require(customConfigPath); - if (customConfig.module.loaders) { - logger.info('=> Loading custom webpack loaders.'); - _webpack4.default.module.loaders = _webpack4.default.module.loaders.concat(customConfig.module.loaders); - } - - if (customConfig.plugins) { - logger.info(' => Loading custom webpack plugins.'); - _webpack4.default.plugins = _webpack4.default.plugins.concat(customConfig.plugins); - } + logger.info('=> Loading custom webpack config.'); + finalConfig = (0, _extends3.default)({}, customConfig, _webpack4.default, { + plugins: [].concat((0, _toConsumableArray3.default)(_webpack4.default.plugins), (0, _toConsumableArray3.default)(customConfig.plugins)), + module: (0, _extends3.default)({}, _webpack4.default.module, { + loaders: [].concat((0, _toConsumableArray3.default)(_webpack4.default.module.loaders), (0, _toConsumableArray3.default)(customConfig.module.loaders)) + }) + }); + finalConfig.resolve.modulesDirectories.push('node_modules'); } -var compiler = (0, _webpack2.default)(_webpack4.default); +var compiler = (0, _webpack2.default)(finalConfig); var devMiddlewareOptions = { noInfo: true, - publicPath: _webpack4.default.output.publicPath + publicPath: finalConfig.output.publicPath }; app.use((0, _webpackDevMiddleware2.default)(compiler, devMiddlewareOptions)); app.use((0, _webpackHotMiddleware2.default)(compiler)); diff --git a/src/server/index.js b/src/server/index.js index e961023d81b7..c7e55756eaf2 100755 --- a/src/server/index.js +++ b/src/server/index.js @@ -69,24 +69,31 @@ config.entry.preview.push(storybookConfigPath); // load custom webpack configurations const customConfigPath = path.resolve(configDirPath, 'webpack.config.js'); +let finalConfig = config; if (fs.existsSync(customConfigPath)) { const customConfig = require(customConfigPath); - if (customConfig.module.loaders) { - logger.info('=> Loading custom webpack loaders.'); - config.module.loaders = - config.module.loaders.concat(customConfig.module.loaders); - } - - if (customConfig.plugins) { - logger.info(' => Loading custom webpack plugins.'); - config.plugins = config.plugins.concat(customConfig.plugins); - } + logger.info('=> Loading custom webpack config.'); + finalConfig = { + ...customConfig, + ...config, + plugins: [ + ...config.plugins, + ...customConfig.plugins + ], + module: { + ...config.module, + loaders: [ + ...config.module.loaders, + ...customConfig.module.loaders + ] + } + }; } -const compiler = webpack(config); +const compiler = webpack(finalConfig); const devMiddlewareOptions = { noInfo: true, - publicPath: config.output.publicPath, + publicPath: finalConfig.output.publicPath, }; app.use(webpackDevMiddleware(compiler, devMiddlewareOptions)); app.use(webpackHotMiddleware(compiler));