Skip to content
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

making it so it requires all the webpack config #64

Merged
merged 1 commit into from
Apr 6, 2016
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
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