base.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const path = require('path');
  2. const _ = require('lodash');
  3. const chalk = require('chalk').default;
  4. const utils = require('./utils');
  5. let AnalyzePlugin = null
  6. if(process.env.__ENABLE_ANALYZE__ === 'true') {
  7. AnalyzePlugin = require("@ies/semi-page-analyze-inject/src/AnalyzePlugin")
  8. }
  9. function resolve(...dirs) {
  10. return path.join(__dirname, '../..', ...dirs);
  11. }
  12. /**
  13. * 当我们想获取 Cypress 代码覆盖率时,需要将 TEST_ENV 设置为 true。
  14. *
  15. * 这时会打开 babel-loader 配置,去掉 esbuild 配置,并在 babel plugin 中注入 babel-plugin-istanbul
  16. *
  17. * @see https://github.com/istanbuljs/babel-plugin-istanbul
  18. */
  19. function getAddons() {
  20. let addons = [
  21. // for performance reason, only open `@storybook/addon-a11y` when dev a11y
  22. // '@storybook/addon-a11y',
  23. '@storybook/addon-toolbars',
  24. ];
  25. if (!utils.isTest()) {
  26. console.log(chalk.yellow(`if you want to get cypress code coverage, set TEST_ENV=test, now it is '${process.env.TEST_ENV}'`));
  27. }
  28. return addons;
  29. }
  30. module.exports = {
  31. framework: {
  32. name: "@storybook/react-webpack5",
  33. options: {
  34. fastRefresh: true
  35. },
  36. },
  37. addons: getAddons(),
  38. webpackFinal: async (config) => {
  39. const rules =
  40. (config.module.rules &&
  41. config.module.rules.filter(rule => {
  42. const test = _.toString(rule && rule.test);
  43. if (/\.css/i.test(test) || /\.s(c|a)ss/i.test(test)) {
  44. return false;
  45. }
  46. return true;
  47. })) ||
  48. [];
  49. rules.push(
  50. {
  51. test: /\.css$/,
  52. use: ['style-loader', 'css-loader']
  53. },
  54. );
  55. rules.push(
  56. {
  57. test: /\.s(a|c)ss$/,
  58. include: [resolve('packages/semi-ui'), resolve('packages/semi-foundation'), resolve('packages/semi-icons')],
  59. use: ['style-loader', 'css-loader', 'sass-loader', resolve('packages/semi-webpack/lib/semi-theme-loader.js')],
  60. }
  61. );
  62. AnalyzePlugin && rules.push({
  63. test: /\.tsx?$/,
  64. exclude: /node_modules/,
  65. use: [
  66. {
  67. loader: "babel-loader",
  68. options: {
  69. plugins: [AnalyzePlugin],
  70. }
  71. },
  72. ]
  73. })
  74. config.module.rules = rules;
  75. config.resolve.extensions.push('.js', '.jsx', '.ts', '.tsx');
  76. config.resolve.symlinks = false;
  77. config.mode = "development";
  78. config.resolve.alias = {
  79. '@douyinfe/semi-foundation': resolve('packages/semi-foundation'),
  80. '@douyinfe/semi-icons': resolve('packages/semi-icons/src'),
  81. '@douyinfe/semi-ui': resolve('packages/semi-ui'),
  82. '@douyinfe/semi-theme-default': resolve('packages/semi-theme-default'),
  83. '@douyinfe/semi-illustrations': resolve('packages/semi-illustrations/src'),
  84. '@douyinfe/semi-animation': resolve('packages/semi-animation'),
  85. '@douyinfe/semi-animation-react': resolve('packages/semi-animation-react'),
  86. '@douyinfe/semi-animation-styled': resolve('packages/semi-animation-styled')
  87. };
  88. config.devtool = 'source-map';
  89. // config.output.publicPath = "/storybook/"
  90. return config;
  91. }
  92. };