webpack.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0 */
  3. const path = require('path');
  4. const webpack = require('webpack');
  5. const appConfig = require('../webpack.config');
  6. const staticPath = path.resolve(__dirname, '..', 'static', 'app');
  7. /**
  8. * Default the config parameter that storybook passes into our webpack config
  9. * to an empty object specifically for eslint, since it will load this config
  10. * without passing in a config object.
  11. */
  12. const emptyConfig = {
  13. module: {rules: []},
  14. resolve: {alias: {}, extensions: []},
  15. plugins: [],
  16. };
  17. module.exports = ({config} = {config: emptyConfig}) => {
  18. const [firstRule, ...rules] = config.module.rules;
  19. const filteredRules = rules.filter(rule => {
  20. return (
  21. (!rule.loader || !rule.loader.includes('file-loader')) &&
  22. (!Array.isArray(rule.use) ||
  23. !rule.use.find(({loader}) => loader && loader.includes('postcss-loader')))
  24. );
  25. });
  26. const newConfig = {
  27. ...config,
  28. module: {
  29. ...config.module,
  30. rules: [
  31. {
  32. ...firstRule,
  33. test: /\.(mjs|[tj]sx?)$/,
  34. include: [path.join(__dirname), staticPath, path.join(__dirname, '../docs-ui')],
  35. },
  36. {
  37. test: /\.less$/,
  38. use: ['style-loader', 'css-loader', 'less-loader'],
  39. },
  40. {
  41. test: /\.pegjs/,
  42. use: {loader: 'pegjs-loader'},
  43. },
  44. {
  45. test: /\.(woff|woff2|ttf|eot|svg|png|gif|ico|jpg)($|\?)/,
  46. use: [
  47. {
  48. loader: 'file-loader',
  49. options: {
  50. esModule: false,
  51. name: '[name].[hash:6].[ext]',
  52. },
  53. },
  54. ],
  55. },
  56. {
  57. test: /\.po$/,
  58. use: {
  59. loader: 'po-catalog-loader',
  60. options: {
  61. referenceExtensions: ['.js', '.jsx'],
  62. domain: 'sentry',
  63. },
  64. },
  65. },
  66. ...filteredRules,
  67. ],
  68. },
  69. plugins: [
  70. ...config.plugins,
  71. new webpack.ProvidePlugin({
  72. jQuery: 'jquery',
  73. }),
  74. new webpack.DefinePlugin({
  75. 'process.env.FIXED_DYNAMIC_CONTENT': true,
  76. }),
  77. ],
  78. resolve: {
  79. ...config.resolve,
  80. extensions: Array.from(
  81. new Set([...config.resolve.extensions, ...appConfig.resolve.extensions])
  82. ),
  83. alias: {
  84. ...config.resolve.alias,
  85. ...appConfig.resolve.alias,
  86. app: staticPath,
  87. },
  88. fallback: {
  89. ...appConfig.resolve.fallback,
  90. // XXX(epurkhiser): As per [0] assert is required for
  91. // @storybook/addons-docs, but seems we can just noop the pollyfill.
  92. //
  93. // [0]: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#gistcomment-3681971
  94. assert: false,
  95. },
  96. },
  97. };
  98. return newConfig;
  99. };