main.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // eslint-disable-next-line no-constant-condition
  10. while (true) {
  11. if (fs.existsSync(path.join(currDir, 'package.json'))) {
  12. return currDir
  13. }
  14. const { dir, root } = path.parse(currDir)
  15. if (dir === root) {
  16. throw new Error(`Could not find package.json in the parent directories starting from ${filepath}.`)
  17. }
  18. currDir = dir
  19. }
  20. }
  21. module.exports = {
  22. stories: ['./Welcome.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
  23. addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/preset-create-react-app'],
  24. webpackFinal: async (config) => {
  25. const craConfig = reactConfig.webpack(config)
  26. return merge(craConfig, {
  27. resolve: {
  28. alias: {
  29. '@emotion/core': getPackageDir('@emotion/react'),
  30. '@emotion/styled': getPackageDir('@emotion/styled'),
  31. 'emotion-theming': getPackageDir('@emotion/react'),
  32. },
  33. },
  34. })
  35. },
  36. }