webpack.config.dev.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // if WEBPACK_ENTRYPOINTS is defined, remove any entrypoints that aren't included
  8. if (process.env.WEBPACK_ENTRYPOINTS) {
  9. const entrypoints = new Set(process.env.WEBPACK_ENTRYPOINTS.split(/\s*,\s*/))
  10. console.log(`Building entrypoints ${[...entrypoints].join(',')}`)
  11. for (const entrypoint in base.entry) {
  12. if (!entrypoints.has(entrypoint)) {
  13. delete base.entry[entrypoint]
  14. }
  15. }
  16. }
  17. module.exports = merge(base, {
  18. mode: 'development',
  19. // Enable accurate source maps for dev
  20. devtool:
  21. process.env.CSP_ENABLED === 'true' ? 'source-map' : 'eval-source-map',
  22. // Load entrypoints without contenthash in filename
  23. output: {
  24. filename: 'js/[name].js',
  25. },
  26. // Load assets without contenthash in filename
  27. module: {
  28. rules: [
  29. {
  30. test: /\.(woff|woff2)$/,
  31. type: 'asset/resource',
  32. generator: {
  33. filename: 'fonts/[name][ext]',
  34. },
  35. },
  36. {
  37. test: /\.(svg|gif|png|jpg|pdf)$/,
  38. type: 'asset/resource',
  39. generator: {
  40. filename: 'images/[name][ext]',
  41. },
  42. },
  43. ],
  44. },
  45. plugins: [
  46. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  47. new MiniCssExtractPlugin({
  48. // Output to public/stylesheets directory
  49. filename: 'stylesheets/[name].css',
  50. }),
  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. },
  79. // Customise output to the (node) console
  80. stats: {
  81. preset: 'minimal',
  82. colors: true,
  83. },
  84. })