Skip to content

Commit

Permalink
Load .babelrc file manually and load it. Fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda authored and martinerko committed Apr 5, 2016
1 parent 8093e63 commit b9cec46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"redbox-react": "^1.2.2",
"stack-source-map": "^1.0.4",
"uuid": "^2.0.1",
"webpack": "^1.9.11",
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.2.0"
"webpack": "^1.12.11",
"webpack-dev-middleware": "^1.6.0",
"webpack-hot-middleware": "^2.10.0"
},
"peerDependencies": {
"react": "^0.14.7",
Expand Down
21 changes: 18 additions & 3 deletions src/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,23 @@ const config = {
},
};

// add config path to the entry
const configDir = path.resolve('./.storybook');

// load babelrc file.
const babelrcPath = path.resolve('./.babelrc');
if (fs.existsSync(babelrcPath)) {
logger.info('=> Using custom .babelrc configurations.');
const babelrcContent = fs.readFileSync(babelrcPath);
try {
const babelrc = JSON.parse(babelrcContent);
config.module.loaders[0].query = babelrc;
} catch (ex) {
logger.error(`=> Error parsing .babelrc file: ${ex.message}`);
throw ex;
}
}

// add config path to the entry
const storybookConfigPath = path.resolve(configDir, 'config.js');
if (!fs.existsSync(storybookConfigPath)) {
logger.error('=> Create a storybook config file in ".storybook/config.js".\n');
Expand All @@ -53,13 +68,13 @@ const customConfigPath = path.resolve(configDir, 'webpack.config.js');
if (fs.existsSync(customConfigPath)) {
const customConfig = require(customConfigPath);
if (customConfig.module.loaders) {
logger.log('=> Loading custom webpack loaders.');
logger.info('=> Loading custom webpack loaders.');
config.module.loaders =
config.module.loaders.concat(customConfig.module.loaders);
}

if (customConfig.plugins) {
logger.log(' => Loading custom webpack plugins.');
logger.info(' => Loading custom webpack plugins.');
config.plugins = config.plugins.concat(customConfig.plugins);
}
}
Expand Down

0 comments on commit b9cec46

Please sign in to comment.