webpack.config.dev.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. process.env.REACT_REFRESH = '1'
  6. const base = require('./webpack.config')
  7. module.exports = merge(base, {
  8. mode: 'development',
  9. // Enable accurate source maps for dev
  10. devtool:
  11. process.env.CSP_ENABLED === 'true' ? 'source-map' : 'eval-source-map',
  12. // Load entrypoints without contenthash in filename
  13. output: {
  14. filename: 'js/[name].js',
  15. },
  16. // Load assets without contenthash in filename
  17. module: {
  18. rules: [
  19. {
  20. test: /\.(woff|woff2)$/,
  21. type: 'asset/resource',
  22. generator: {
  23. filename: 'fonts/[name][ext]',
  24. },
  25. },
  26. {
  27. test: /\.(svg|gif|png|jpg|pdf)$/,
  28. type: 'asset/resource',
  29. generator: {
  30. filename: 'images/[name][ext]',
  31. },
  32. },
  33. ],
  34. },
  35. plugins: [
  36. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  37. new MiniCssExtractPlugin({
  38. // Output to public/stylesheets directory
  39. filename: 'stylesheets/[name].css',
  40. }),
  41. new ReactRefreshWebpackPlugin({
  42. exclude: [
  43. /node_modules/, // default
  44. /source-editor/, // avoid crashing the source editor
  45. ],
  46. }),
  47. // Disable React DevTools if DISABLE_REACT_DEVTOOLS is set to "true"
  48. process.env.DISABLE_REACT_DEVTOOLS === 'true' &&
  49. new webpack.DefinePlugin({
  50. __REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })',
  51. }),
  52. ].filter(Boolean),
  53. devServer: {
  54. // Expose dev server at www.dev-overleaf.com
  55. host: '0.0.0.0',
  56. port: parseInt(process.env.PORT, 10) || 3808,
  57. client: {
  58. webSocketURL: 'auto://0.0.0.0:0/ws',
  59. },
  60. hot: true,
  61. allowedHosts: '.dev-overleaf.com',
  62. setupMiddlewares(middlewares, devServer) {
  63. devServer.app.get('/status', (req, res) => res.send('webpack is up'))
  64. return middlewares
  65. },
  66. },
  67. // Customise output to the (node) console
  68. stats: {
  69. preset: 'minimal',
  70. colors: true,
  71. },
  72. })