webpack.config.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: /\.(woff|woff2|ttf|eot|svg|png|gif|ico|jpg)($|\?)/,
  42. use: [
  43. {
  44. loader: 'file-loader',
  45. options: {
  46. esModule: false,
  47. name: '[name].[hash:6].[ext]',
  48. },
  49. },
  50. ],
  51. },
  52. {
  53. test: /\.po$/,
  54. use: {
  55. loader: 'po-catalog-loader',
  56. options: {
  57. referenceExtensions: ['.js', '.jsx'],
  58. domain: 'sentry',
  59. },
  60. },
  61. },
  62. ...filteredRules,
  63. ],
  64. },
  65. plugins: [
  66. ...config.plugins,
  67. new webpack.ProvidePlugin({
  68. jQuery: 'jquery',
  69. }),
  70. new webpack.DefinePlugin({
  71. 'process.env.FIXED_DYNAMIC_CONTENT': true,
  72. }),
  73. ],
  74. resolve: {
  75. ...config.resolve,
  76. extensions: Array.from(
  77. new Set([...config.resolve.extensions, ...appConfig.resolve.extensions])
  78. ),
  79. alias: {
  80. ...config.resolve.alias,
  81. ...appConfig.resolve.alias,
  82. app: staticPath,
  83. },
  84. fallback: {
  85. ...appConfig.resolve.fallback,
  86. },
  87. },
  88. };
  89. return newConfig;
  90. };