webpack.config.dev.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const { merge } = require('webpack-merge')
  4. const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  5. const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
  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. cache: {
  23. type: 'filesystem',
  24. buildDependencies: {
  25. config: [
  26. __filename,
  27. path.resolve(__dirname, 'webpack.config.js'),
  28. path.resolve(__dirname, 'config/settings.webpack.js'),
  29. ],
  30. },
  31. },
  32. // Load entrypoints without contenthash in filename
  33. output: {
  34. filename: 'js/[name].js',
  35. },
  36. // Load assets without contenthash in filename
  37. module: {
  38. rules: [
  39. {
  40. test: /\.(woff|woff2)$/,
  41. type: 'asset/resource',
  42. generator: {
  43. filename: 'fonts/[name][ext]',
  44. },
  45. },
  46. {
  47. test: /\.(svg|gif|png|jpg|pdf)$/,
  48. type: 'asset/resource',
  49. generator: {
  50. filename: 'images/[name][ext]',
  51. },
  52. },
  53. ],
  54. },
  55. plugins: [
  56. // Extract CSS to a separate file (rather than inlining to a <style> tag)
  57. new MiniCssExtractPlugin({
  58. // Output to public/stylesheets directory
  59. filename: 'stylesheets/[name].css',
  60. }),
  61. process.env.REACT_REFRESH_ENABLED === 'true' &&
  62. new ReactRefreshWebpackPlugin({
  63. exclude: [
  64. /node_modules/, // default
  65. /source-editor/, // avoid crashing the source editor
  66. ],
  67. overlay: false,
  68. }),
  69. // Disable React DevTools if DISABLE_REACT_DEVTOOLS is set to "true"
  70. process.env.DISABLE_REACT_DEVTOOLS === 'true' &&
  71. new webpack.DefinePlugin({
  72. __REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })',
  73. }),
  74. ].filter(Boolean),
  75. devServer: {
  76. // Expose dev server at www.dev-overleaf.com
  77. host: '0.0.0.0',
  78. port: parseInt(process.env.PORT, 10) || 3808,
  79. client: {
  80. webSocketURL: 'auto://0.0.0.0:0/ws',
  81. overlay: process.env.DISABLE_WEBPACK_OVERLAY !== 'true',
  82. },
  83. hot: true,
  84. allowedHosts: '.dev-overleaf.com',
  85. setupMiddlewares(middlewares, devServer) {
  86. devServer.app.get('/status', (req, res) => res.send('webpack is up'))
  87. return middlewares
  88. },
  89. compress: false,
  90. },
  91. // Customise output to the (node) console
  92. stats: {
  93. preset: 'minimal',
  94. colors: true,
  95. },
  96. ignoreWarnings: [
  97. // ignore some "Can't resolve '*'" warnings for dynamically-imported optional peer dependencies
  98. /@ai-sdk\/provider-utils\/dist/,
  99. ],
  100. })