webpack.config.dev.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const webpack = require('webpack')
  2. const { merge } = require('webpack-merge')
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  4. const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
  5. const base = require('./webpack.config')
  6. // if WEBPACK_ENTRYPOINTS is defined, remove any entrypoints that aren't included
  7. if (process.env.WEBPACK_ENTRYPOINTS) {
  8. const entrypoints = new Set(process.env.WEBPACK_ENTRYPOINTS.split(/\s*,\s*/))
  9. console.log(`Building entrypoints ${[...entrypoints].join(',')}`)
  10. for (const entrypoint in base.entry) {
  11. if (!entrypoints.has(entrypoint)) {
  12. delete base.entry[entrypoint]
  13. }
  14. }
  15. }
  16. module.exports = merge(base, {
  17. mode: 'development',
  18. // Enable accurate source maps for dev
  19. devtool:
  20. process.env.CSP_ENABLED === 'true' ? 'source-map' : 'eval-source-map',
  21. // Load entrypoints without contenthash in filename
  22. output: {
  23. filename: 'js/[name].js',
  24. },
  25. // Load assets without contenthash in filename
  26. module: {
  27. rules: [
  28. {
  29. test: /\.(woff|woff2)$/,
  30. type: 'asset/resource',
  31. generator: {
  32. filename: 'fonts/[name][ext]',
  33. },
  34. },
  35. {
  36. test: /\.(svg|gif|png|jpg|pdf)$/,
  37. type: 'asset/resource',
  38. generator: {
  39. filename: 'images/[name][ext]',
  40. },
  41. },
  42. ],
  43. },
  44. plugins: [
  45. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  46. new MiniCssExtractPlugin({
  47. // Output to public/stylesheets directory
  48. filename: 'stylesheets/[name].css',
  49. }),
  50. process.env.REACT_REFRESH_ENABLED === 'true' &&
  51. new ReactRefreshWebpackPlugin({
  52. exclude: [
  53. /node_modules/, // default
  54. /source-editor/, // avoid crashing the source editor
  55. ],
  56. overlay: false,
  57. }),
  58. // Disable React DevTools if DISABLE_REACT_DEVTOOLS is set to "true"
  59. process.env.DISABLE_REACT_DEVTOOLS === 'true' &&
  60. new webpack.DefinePlugin({
  61. __REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })',
  62. }),
  63. ].filter(Boolean),
  64. devServer: {
  65. // Expose dev server at www.dev-overleaf.com
  66. host: '0.0.0.0',
  67. port: parseInt(process.env.PORT, 10) || 3808,
  68. client: {
  69. webSocketURL: 'auto://0.0.0.0:0/ws',
  70. overlay: process.env.DISABLE_WEBPACK_OVERLAY !== 'true',
  71. },
  72. hot: true,
  73. allowedHosts: '.dev-overleaf.com',
  74. setupMiddlewares(middlewares, devServer) {
  75. devServer.app.get('/status', (req, res) => res.send('webpack is up'))
  76. return middlewares
  77. },
  78. compress: false,
  79. },
  80. // Customise output to the (node) console
  81. stats: {
  82. preset: 'minimal',
  83. colors: true,
  84. },
  85. ignoreWarnings: [
  86. // ignore some "Can't resolve '*'" warnings for dynamically-imported optional peer dependencies
  87. /@ai-sdk\/provider-utils\/dist/,
  88. ],
  89. })