mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-01 05:05:25 +08:00
Load .babelrc file manually and load it. Fixes #41
This commit is contained in:
parent
8093e6324e
commit
b9cec46828
@ -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",
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user