Skip to content

Commit

Permalink
making it so it requires all the webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
eloytoro committed Apr 6, 2016
1 parent b110b27 commit bfed1eb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
30 changes: 19 additions & 11 deletions dist/server/index.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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));
Expand Down
31 changes: 19 additions & 12 deletions src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit bfed1eb

Please sign in to comment.