webpack.config.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const path = require('path')
  2. const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
  3. module.exports = ({ config }) => {
  4. // Styles (replace the provided rule):
  5. const originalCssRuleIndex = config.module.rules.findIndex(rule => rule.test.source.includes('.css'));
  6. config.module.rules[originalCssRuleIndex] = {
  7. test: /\.(sa|sc|c)ss$/i,
  8. use: [
  9. // Creates `style` nodes from JS strings
  10. 'style-loader',
  11. // Translates CSS into CommonJS
  12. 'css-loader',
  13. // Compiles Sass to CSS
  14. 'sass-loader'
  15. ]
  16. };
  17. // TypeScript loader (via Babel to match polkadot/apps)
  18. config.module.rules.push({
  19. test: /\.(js|ts|tsx)$/,
  20. exclude: /(node_modules)/,
  21. use: [
  22. {
  23. loader: require.resolve('babel-loader'),
  24. options: require('@polkadot/dev/config/babel')
  25. },
  26. ],
  27. });
  28. config.resolve.extensions.push('.js', '.ts', '.tsx');
  29. // TSConfig, uses the same file as packages
  30. config.resolve.plugins = config.resolve.plugins || [];
  31. config.resolve.plugins.push(
  32. new TsconfigPathsPlugin({
  33. configFile: path.resolve(__dirname, '../tsconfig.json'),
  34. })
  35. );
  36. // Stories parser
  37. config.module.rules.push({
  38. test: /\.stories\.tsx?$/,
  39. loaders: [require.resolve('@storybook/source-loader')],
  40. enforce: 'pre',
  41. });
  42. return config;
  43. };