webpack.config.dev.js 3.5 KB

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