Files
overleaf-cep/services/web/webpack.config.dev.js
Kristina b3beca0e8d [web] isolate cypress webpack caches (#33516)
GitOrigin-RevId: 65f8bf162df4fa3b67c8ac19f36fd578251e88f4
2026-05-12 08:05:24 +00:00

128 lines
3.5 KiB
JavaScript

const path = require('path')
const webpack = require('webpack')
const { merge } = require('webpack-merge')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
const base = require('./webpack.config')
const cypressCacheVariant = require('./frontend/macros/cypress-cache-variant')
const cypressVariant = cypressCacheVariant()
// if WEBPACK_ENTRYPOINTS is defined, remove any entrypoints that aren't included
if (process.env.WEBPACK_ENTRYPOINTS) {
const entrypoints = new Set(process.env.WEBPACK_ENTRYPOINTS.split(/\s*,\s*/))
console.log(`Building entrypoints ${[...entrypoints].join(',')}`)
for (const entrypoint in base.entry) {
if (!entrypoints.has(entrypoint)) {
delete base.entry[entrypoint]
}
}
}
module.exports = merge(base, {
mode: 'development',
// Enable accurate source maps for dev
devtool:
process.env.CSP_ENABLED === 'true' ? 'source-map' : 'eval-source-map',
cache: {
type: 'filesystem',
// Use a unique cache directory per Cypress CT variant to avoid
// parallel jobs corrupting the shared PackFileCacheStrategy pack files.
...(cypressVariant
? {
cacheDirectory: path.resolve(
__dirname,
'node_modules/.cache/webpack',
cypressVariant
),
}
: {}),
buildDependencies: {
config: [
__filename,
path.resolve(__dirname, 'webpack.config.js'),
path.resolve(__dirname, 'config/settings.webpack.js'),
],
},
},
// Load entrypoints without contenthash in filename
output: {
filename: 'js/[name].js',
},
// Load assets without contenthash in filename
module: {
rules: [
{
test: /\.(woff|woff2)$/,
type: 'asset/resource',
generator: {
filename: 'fonts/[name][ext]',
},
},
{
test: /\.(svg|gif|png|jpg|pdf)$/,
type: 'asset/resource',
generator: {
filename: 'images/[name][ext]',
},
},
],
},
plugins: [
// Extract CSS to a separate file (rather than inlining to a <style> tag)
new MiniCssExtractPlugin({
// Output to public/stylesheets directory
filename: 'stylesheets/[name].css',
}),
process.env.REACT_REFRESH_ENABLED === 'true' &&
new ReactRefreshWebpackPlugin({
exclude: [
/node_modules/, // default
/source-editor/, // avoid crashing the source editor
],
overlay: false,
}),
// Disable React DevTools if DISABLE_REACT_DEVTOOLS is set to "true"
process.env.DISABLE_REACT_DEVTOOLS === 'true' &&
new webpack.DefinePlugin({
__REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })',
}),
].filter(Boolean),
devServer: {
// Expose dev server at www.dev-overleaf.com
host: '0.0.0.0',
port: parseInt(process.env.PORT, 10) || 3808,
client: {
webSocketURL: 'auto://0.0.0.0:0/ws',
overlay: process.env.DISABLE_WEBPACK_OVERLAY !== 'true',
},
hot: true,
allowedHosts: '.dev-overleaf.com',
setupMiddlewares(middlewares, devServer) {
devServer.app.get('/status', (req, res) => res.send('webpack is up'))
return middlewares
},
compress: false,
},
// Customise output to the (node) console
stats: {
preset: 'minimal',
colors: true,
},
ignoreWarnings: [
// ignore some "Can't resolve '*'" warnings for dynamically-imported optional peer dependencies
/@ai-sdk\/provider-utils\/dist/,
],
})