BVB Source Codes

storybook Show config.js Source code

Return Download storybook: download config.js Source code - Download storybook Source code - Type:.js
  1. import fs from 'fs';
  2. import path from 'path';
  3. import loadBabelConfig from './babel_config';
  4.  
  5. // avoid ESLint errors
  6. const logger = console;
  7.  
  8. // `baseConfig` is a webpack configuration bundled with storybook.
  9. // Storybook will look in the `configDir` directory
  10. // (inside working directory) if a config path is not provided.
  11. export default function(configType, baseConfig, configDir) {
  12.   const config = baseConfig;
  13.  
  14.   const babelConfig = loadBabelConfig(configDir);
  15.   config.module.rules[0].query = babelConfig;
  16.  
  17.   // Check whether a config.js file exists inside the storybook
  18.   // config directory and throw an error if it's not.
  19.   const storybookConfigPath = path.resolve(configDir, 'config.js');
  20.   if (!fs.existsSync(storybookConfigPath)) {
  21.     const err = new Error(`=> Create a storybook config file in "${configDir}/config.js".`);
  22.     throw err;
  23.   }
  24.   config.entry.preview.push(require.resolve(storybookConfigPath));
  25.  
  26.   // Check whether addons.js file exists inside the storybook.
  27.   // Load the default addons.js file if it's missing.
  28.   const storybookDefaultAddonsPath = path.resolve(__dirname, 'addons.js');
  29.   const storybookCustomAddonsPath = path.resolve(configDir, 'addons.js');
  30.   if (fs.existsSync(storybookCustomAddonsPath)) {
  31.     logger.info('=> Loading custom addons config.');
  32.     config.entry.manager.unshift(storybookCustomAddonsPath);
  33.   } else {
  34.     config.entry.manager.unshift(storybookDefaultAddonsPath);
  35.   }
  36.  
  37.   // Check whether user has a custom webpack config file and
  38.   // return the (extended) base configuration if it's not available.
  39.   const customConfigPath = path.resolve(configDir, 'webpack.config.js');
  40.  
  41.   if (!fs.existsSync(customConfigPath)) {
  42.     logger.info('=> Using default webpack setup based on "Create React App".');
  43.     const configPath = path.resolve(__dirname, './config/defaults/webpack.config.js');
  44.     const customConfig = require(configPath);
  45.  
  46.     return customConfig(config);
  47.   } else {
  48.     const customConfig = require(customConfigPath);
  49.  
  50.     if (typeof customConfig === 'function') {
  51.       logger.info('=> Loading custom webpack config (full-control mode).');
  52.       return customConfig(config, configType);
  53.     } else {
  54.       logger.info('=> Loading custom webpack config (extending mode).');
  55.       return {
  56.         ...customConfig,
  57.         // We'll always load our configurations after the custom config.
  58.         // So, we'll always load the stuff we need.
  59.         ...config,
  60.         // Override with custom devtool if provided
  61.         devtool: customConfig.devtool || config.devtool,
  62.         // We need to use our and custom plugins.
  63.         plugins: [...config.plugins, ...(customConfig.plugins || [])],
  64.         module: {
  65.           ...config.module,
  66.           // We need to use our and custom rules.
  67.           ...customConfig.module,
  68.           rules: [...config.module.rules, ...(customConfig.module.rules || [])],
  69.         },
  70.         resolve: {
  71.           ...config.resolve,
  72.           ...customConfig.resolve,
  73.           alias: {
  74.             ...config.alias,
  75.             ...(customConfig.resolve && customConfig.resolve.alias),
  76.           },
  77.         },
  78.       };
  79.     }
  80.   }
  81. }
  82.  
downloadconfig.js Source code - Download storybook Source code
Related Source Codes/Software:
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top