From 43e88709136ffa5d439ec6e4d9bb3144caf12c2b Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 4 Apr 2016 22:40:36 +0530 Subject: [PATCH] Load .babelrc file manually and load it. Fixes #41 --- package.json | 6 +++--- src/server/webpack.config.js | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 89df0fb9e9c8..fa2b8a9e7dce 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/server/webpack.config.js b/src/server/webpack.config.js index b33e3011b5c2..4bd1d36e2dba 100644 --- a/src/server/webpack.config.js +++ b/src/server/webpack.config.js @@ -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'); @@ -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); } }