No Description

webpack.config.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const fs = require('fs');
  2. const path = require('path');
  3. module.exports = ({ config }) => {
  4. config.resolve.modules = ['node_modules'];
  5. config.module.rules.push({
  6. test: /\.stories\.tsx?$/,
  7. loaders: [require.resolve('@storybook/source-loader')],
  8. enforce: 'pre',
  9. });
  10. config.module.rules.push({
  11. test: /\.less$/,
  12. include: /node_modules|antd\.less/,
  13. use: [
  14. "style-loader",
  15. "css-loader",
  16. {
  17. loader: "less-loader",
  18. options: {
  19. javascriptEnabled: true
  20. }
  21. }
  22. ]
  23. });
  24. config.module.rules.push({
  25. test: /\.less$/,
  26. use: [
  27. 'style-loader',
  28. {
  29. loader: 'css-loader',// translates CSS into CommonJS
  30. options: {
  31. modules: {
  32. localIdentName: '[name]__[local]___[hash:base64:5]',
  33. },
  34. }
  35. },
  36. 'postcss-loader',
  37. {
  38. loader: 'less-loader',
  39. options: {
  40. config: {
  41. path: path.join(path.resolve(__dirname, '..'), 'postcss.config.js')
  42. },
  43. javascriptEnabled: true,
  44. },
  45. }],
  46. exclude: /node_modules|antd\.less/,
  47. });
  48. config.module.rules.push({
  49. test: /\.(ts|tsx)$/,
  50. use: [
  51. // Optional
  52. {
  53. loader: require.resolve("react-docgen-typescript-loader"),
  54. options: {
  55. // Provide the path to your tsconfig.json so that your stories can
  56. // display types from outside each individual story.
  57. tsconfigPath: path.resolve(__dirname, "../tsconfig.json"),
  58. },
  59. },
  60. {
  61. loader: require.resolve('babel-loader'),
  62. options: {
  63. presets: [['react-app', { flow: false, typescript: true }]],
  64. }
  65. },
  66. ]
  67. });
  68. config.resolve.extensions.push(".ts", ".tsx");
  69. config.resolve.alias = {
  70. ...config.resolve.alias,
  71. '@': `${path.resolve(fs.realpathSync(process.cwd()), './src')}`,
  72. '@components': `${path.resolve(fs.realpathSync(process.cwd()), './src')}/components`,
  73. }
  74. config.output.library = "[name]";
  75. return config;
  76. };