diff --git a/services/web/babel.config.cjs b/services/web/babel.config.cjs new file mode 100644 index 0000000000..6a12a8e8ce --- /dev/null +++ b/services/web/babel.config.cjs @@ -0,0 +1,41 @@ +module.exports = { + compact: false, + presets: [ + [ + '@babel/env', + { + useBuiltIns: 'usage', + // This version must be aligned with the `core-js` version in `package.json` + corejs: { version: '3.46' }, + exclude: [ + // Exclude Array.prototype.push polyfill, as it's not needed and affects performance in Chrome + 'es.array.push', + // Exclude objectSpread polyfill, as it's not needed and affects performance + '@babel/plugin-transform-object-rest-spread', + // Exclude _defineProperty polyfill, as it causes a bug without the objectSpread polyfill + '@babel/plugin-transform-computed-properties', + // Use native async functions, for performance + '@babel/plugin-transform-async-to-generator', + // Use native generators, for performance + '@babel/plugin-transform-regenerator', + // Use native async generators, for performance + '@babel/plugin-transform-async-generator-functions', + // Use native for-of loops, for performance + '@babel/plugin-transform-for-of', + ], + }, + ], + ['@babel/react', { runtime: 'automatic' }], + '@babel/typescript', + ], + plugins: ['macros'], + overrides: [ + // treat .cjs files (e.g. libraries symlinked into node_modules) as commonjs + { test: /\.cjs$/, sourceType: 'script' }, + { + // Use [\\/] for cross-platform path separator compatibility + test: /[\\/]libraries[\\/]overleaf-editor-core[\\/].*\.js$/, + sourceType: 'script', + }, + ], +} diff --git a/services/web/babel.config.json b/services/web/babel.config.json deleted file mode 100644 index ea32ea0299..0000000000 --- a/services/web/babel.config.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "compact": false, - "presets": [ - [ - "@babel/env", - { - "useBuiltIns": "usage", - // This version must be aligned with the `core-js` version in `package.json` - "corejs": { "version": "3.46" }, - "exclude": [ - // Exclude Array.prototype.push polyfill, as it's not needed and affects performance in Chrome - "es.array.push", - // Exclude objectSpread polyfill, as it's not needed and affects performance - "@babel/plugin-transform-object-rest-spread", - // Exclude _defineProperty polyfill, as it causes a bug without the objectSpread polyfill - "@babel/plugin-transform-computed-properties", - // Use native async functions, for performance - "@babel/plugin-transform-async-to-generator", - // Use native generators, for performance - "@babel/plugin-transform-regenerator", - // Use native async generators, for performance - "@babel/plugin-transform-async-generator-functions", - // Use native for-of loops, for performance - "@babel/plugin-transform-for-of" - ] - } - ], - ["@babel/react", { "runtime": "automatic" }], - "@babel/typescript" - ], - "plugins": ["macros"], - "overrides": [ - // treat .cjs files (e.g. libraries symlinked into node_modules) as commonjs - { - "test": "../../**/*.cjs", - "sourceType": "script" - }, - { - "test": "../../libraries/overleaf-editor-core/**/*.js", - "sourceType": "script" - } - ] -} diff --git a/services/web/docker-compose.yml b/services/web/docker-compose.yml index 55e60ce1f8..be82f0432e 100644 --- a/services/web/docker-compose.yml +++ b/services/web/docker-compose.yml @@ -114,7 +114,13 @@ services: - USER_UID - USER_GID volumes: - - ../../:/overleaf + - .:/overleaf/services/web + - ../../node_modules:/overleaf/node_modules + - ../../libraries:/overleaf/libraries + - ../../package.json:/overleaf/package.json + - ../../.yarnrc.yml:/overleaf/.yarnrc.yml + - ../../yarn.lock:/overleaf/yarn.lock + - ../../.yarn:/overleaf/.yarn working_dir: /overleaf/services/web environment: VERBOSE_LOGGING: diff --git a/services/web/webpack.config.js b/services/web/webpack.config.js index 618d787e61..bcb81de06f 100644 --- a/services/web/webpack.config.js +++ b/services/web/webpack.config.js @@ -124,7 +124,7 @@ module.exports = { loader: 'babel-loader', options: { cacheDirectory: true, - configFile: path.join(__dirname, './babel.config.json'), + configFile: path.join(__dirname, './babel.config.cjs'), }, }, { @@ -157,7 +157,7 @@ module.exports = { // Configure babel-loader to cache compiled output so that // subsequent compile runs are much faster cacheDirectory: true, - configFile: path.join(__dirname, './babel.config.json'), + configFile: path.join(__dirname, './babel.config.cjs'), plugins: [ process.env.REACT_REFRESH_ENABLED === 'true' && 'react-refresh/babel',