2021-06-10 10:01:49 +00:00
|
|
|
const webpack = require('webpack')
|
2022-04-06 09:59:13 +00:00
|
|
|
const { merge } = require('webpack-merge')
|
2019-11-28 10:20:22 +00:00
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2022-09-14 11:03:27 +00:00
|
|
|
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')
|
|
|
|
|
|
|
|
process.env.REACT_REFRESH = '1'
|
2018-01-12 11:41:02 +00:00
|
|
|
|
|
|
|
const base = require('./webpack.config')
|
|
|
|
|
2023-07-11 13:38:09 +00:00
|
|
|
// 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]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 11:41:02 +00:00
|
|
|
module.exports = merge(base, {
|
2019-08-06 12:20:02 +00:00
|
|
|
mode: 'development',
|
|
|
|
|
2021-01-06 09:31:57 +00:00
|
|
|
// Enable accurate source maps for dev
|
2023-07-07 06:35:21 +00:00
|
|
|
devtool:
|
|
|
|
process.env.CSP_ENABLED === 'true' ? 'source-map' : 'eval-source-map',
|
2019-08-06 12:20:02 +00:00
|
|
|
|
2022-04-06 17:33:39 +00:00
|
|
|
// 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]',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
2019-11-28 10:20:22 +00:00
|
|
|
plugins: [
|
|
|
|
// Extract CSS to a separate file (rather than inlining to a <style> tag)
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
// Output to public/stylesheets directory
|
2021-04-27 07:52:58 +00:00
|
|
|
filename: 'stylesheets/[name].css',
|
|
|
|
}),
|
2021-06-10 10:01:49 +00:00
|
|
|
|
2022-10-06 08:27:48 +00:00
|
|
|
new ReactRefreshWebpackPlugin({
|
|
|
|
exclude: [
|
|
|
|
/node_modules/, // default
|
|
|
|
/source-editor/, // avoid crashing the source editor
|
|
|
|
],
|
|
|
|
}),
|
2022-09-14 11:03:27 +00:00
|
|
|
|
2021-06-10 10:01:49 +00:00
|
|
|
// Disable React DevTools if DISABLE_REACT_DEVTOOLS is set to "true"
|
2021-06-11 10:17:28 +00:00
|
|
|
process.env.DISABLE_REACT_DEVTOOLS === 'true' &&
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
__REACT_DEVTOOLS_GLOBAL_HOOK__: '({ isDisabled: true })',
|
|
|
|
}),
|
|
|
|
].filter(Boolean),
|
2019-11-28 10:20:22 +00:00
|
|
|
|
2019-08-06 12:20:02 +00:00
|
|
|
devServer: {
|
2021-02-22 15:01:42 +00:00
|
|
|
// Expose dev server at www.dev-overleaf.com
|
2019-08-06 12:20:02 +00:00
|
|
|
host: '0.0.0.0',
|
2022-08-09 12:03:30 +00:00
|
|
|
port: parseInt(process.env.PORT, 10) || 3808,
|
2022-04-06 09:59:13 +00:00
|
|
|
client: {
|
|
|
|
webSocketURL: 'auto://0.0.0.0:0/ws',
|
|
|
|
},
|
2022-09-14 11:03:27 +00:00
|
|
|
hot: true,
|
2022-04-06 09:59:13 +00:00
|
|
|
allowedHosts: '.dev-overleaf.com',
|
|
|
|
setupMiddlewares(middlewares, devServer) {
|
|
|
|
devServer.app.get('/status', (req, res) => res.send('webpack is up'))
|
|
|
|
return middlewares
|
2021-04-27 07:52:58 +00:00
|
|
|
},
|
|
|
|
},
|
2022-04-06 09:59:13 +00:00
|
|
|
|
|
|
|
// Customise output to the (node) console
|
|
|
|
stats: {
|
2023-07-07 06:35:45 +00:00
|
|
|
preset: 'minimal',
|
|
|
|
colors: true,
|
2022-04-06 09:59:13 +00:00
|
|
|
},
|
2023-07-11 13:39:49 +00:00
|
|
|
|
|
|
|
optimization: {
|
2023-10-31 12:16:14 +00:00
|
|
|
runtimeChunk: {
|
|
|
|
name: 'runtime',
|
|
|
|
},
|
2023-07-11 13:39:49 +00:00
|
|
|
},
|
2018-01-12 11:41:02 +00:00
|
|
|
})
|