webpack.config.js 2.5 KB

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