main.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* eslint-disable @typescript-eslint/no-var-requires */
  2. const { merge } = require('webpack-merge')
  3. const path = require('path')
  4. const fs = require('fs')
  5. const reactConfig = require('../config-overrides')
  6. // TODO: related to an issue with emotion and storybook, remove once resolved https://github.com/storybookjs/storybook/issues/7540
  7. function getPackageDir(filepath) {
  8. let currDir = path.dirname(require.resolve(filepath))
  9. while (true) {
  10. if (fs.existsSync(path.join(currDir, 'package.json'))) {
  11. return currDir
  12. }
  13. const { dir, root } = path.parse(currDir)
  14. if (dir === root) {
  15. throw new Error(`Could not find package.json in the parent directories starting from ${filepath}.`)
  16. }
  17. currDir = dir
  18. }
  19. }
  20. module.exports = {
  21. stories: ['./Welcome.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  22. addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/preset-create-react-app'],
  23. webpackFinal: async (config) => {
  24. const craConfig = reactConfig.webpack(config)
  25. return merge(craConfig, {
  26. resolve: {
  27. alias: {
  28. '@emotion/core': getPackageDir('@emotion/react'),
  29. '@emotion/styled': getPackageDir('@emotion/styled'),
  30. 'emotion-theming': getPackageDir('@emotion/react'),
  31. },
  32. },
  33. })
  34. },
  35. }