diff --git a/dev/prod/webpack.config.js b/dev/prod/webpack.config.js index ab94b01e18..c7314cf6a5 100644 --- a/dev/prod/webpack.config.js +++ b/dev/prod/webpack.config.js @@ -17,7 +17,7 @@ const Dotenv = require('dotenv-webpack') const path = require('path') const CompressionPlugin = require('compression-webpack-plugin') const DefinePlugin = require('webpack').DefinePlugin -const HtmlWebpackPlugin = require('html-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin') const { Configuration } = require('webpack') const mode = process.env.NODE_ENV || 'development' @@ -26,17 +26,17 @@ const devServer = (process.env.CLIENT_TYPE ?? '') === 'dev-server' const devProduction = (process.env.CLIENT_TYPE ?? '') === 'dev-production' const devProductionHuly = (process.env.CLIENT_TYPE ?? '') === 'dev-huly' const devProductionBold = (process.env.CLIENT_TYPE ?? '') === 'dev-bold' -const dev = (process.env.CLIENT_TYPE ?? '') === 'dev' || devServer || devProduction || devProductionHuly || devProductionBold -const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); +const dev = + (process.env.CLIENT_TYPE ?? '') === 'dev' || devServer || devProduction || devProductionHuly || devProductionBold +const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin') const { EsbuildPlugin } = require('esbuild-loader') -const doValidate = !prod || (process.env.DO_VALIDATE === 'true') +const doValidate = !prod || process.env.DO_VALIDATE === 'true' const useCache = process.env.USE_CACHE === 'true' -const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; - +const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin /** * @type {Configuration} @@ -77,356 +77,366 @@ module.exports = [ } }, { - cache: useCache ? { - type: 'filesystem', - allowCollectingMemory: true, - cacheLocation: path.resolve(__dirname, '.build_dev'), - }: undefined, - entry: { - bundle: [ - '@hcengineering/theme/styles/global.scss', - ...(dev ? ['./src/main-dev.ts'] : ['./src/main.ts']), - ] - }, - ignoreWarnings: [ - { - message: /a11y-/, + cache: useCache + ? { + type: 'filesystem', + allowCollectingMemory: true, + cacheLocation: path.resolve(__dirname, '.build_dev') + } + : undefined, + entry: { + bundle: ['@hcengineering/theme/styles/global.scss', ...(dev ? ['./src/main-dev.ts'] : ['./src/main.ts'])] }, - /warning from compiler/, - (warning) => true, - ], - resolve: { - symlinks: true, - alias: { - svelte: path.resolve('node_modules', 'svelte/src/runtime'), - '@hcengineering/platform-rig/profiles/ui/svelte': path.resolve('node_modules', 'svelte/src/runtime') - }, - fallback: { - crypto: false - }, - extensions: ['.mjs', '.js', '.svelte', '.ts'], - mainFields: ['svelte', 'browser', 'module', 'main'], - conditionNames: ['svelte', 'browser', 'import'] - }, - output: { - path: __dirname + '/dist', - filename: '[name].[contenthash].js', - chunkFilename: '[name].[contenthash].js', - publicPath: '/', - pathinfo: false - }, - optimization: prod ? { - minimize: true, - minimizer: [ - new EsbuildPlugin({ target: 'es2021' }) - ], - splitChunks: { - chunks: 'all' - } - } : { - minimize: false, - mangleExports: false, - usedExports: false, - splitChunks: { - chunks: 'all' - } - }, - module: { - rules: [ + ignoreWarnings: [ { - test: /\.ts?$/, - loader: 'esbuild-loader', - options: { - target: 'es2021', - keepNames: true, - minify: prod, - sourcemap: true - }, - exclude: /node_modules/, + message: /a11y-/ }, - { - test: /\.svelte$/, - use: [ - { - loader: 'svelte-loader', + /warning from compiler/, + (warning) => true + ], + resolve: { + symlinks: true, + alias: { + svelte: path.resolve('node_modules', 'svelte/src/runtime'), + '@hcengineering/platform-rig/profiles/ui/svelte': path.resolve('node_modules', 'svelte/src/runtime') + }, + fallback: { + crypto: false + }, + extensions: ['.mjs', '.js', '.svelte', '.ts'], + mainFields: ['svelte', 'browser', 'module', 'main'], + conditionNames: ['svelte', 'browser', 'import'] + }, + output: { + path: __dirname + '/dist', + filename: '[name].[contenthash].js', + chunkFilename: '[name].[contenthash].js', + publicPath: '/', + pathinfo: false + }, + optimization: prod + ? { + minimize: true, + minimizer: [new EsbuildPlugin({ target: 'es2021' })], + splitChunks: { + chunks: 'all' + } + } + : { + minimize: false, + mangleExports: false, + usedExports: false, + splitChunks: { + chunks: 'all' + } + }, + module: { + rules: [ + { + test: /\.ts?$/, + loader: 'esbuild-loader', options: { - compilerOptions: { - dev: !prod - }, - emitCss: true, - hotReload: !prod, - preprocess: require('svelte-preprocess')({ - postcss: true, - sourceMap: true, - }), - hotOptions: { - // Prevent preserving local component state - preserveLocalState: true, + target: 'es2021', + keepNames: true, + minify: prod, + sourcemap: true + }, + exclude: /node_modules/ + }, + { + test: /\.svelte$/, + use: [ + { + loader: 'svelte-loader', + options: { + compilerOptions: { + dev: !prod + }, + emitCss: true, + hotReload: !prod, + preprocess: require('svelte-preprocess')({ + postcss: true, + sourceMap: true + }), + hotOptions: { + // Prevent preserving local component state + preserveLocalState: true, - // If this string appears anywhere in your component's code, then local - // state won't be preserved, even when noPreserveState is false - noPreserveStateKey: '@!hmr', + // If this string appears anywhere in your component's code, then local + // state won't be preserved, even when noPreserveState is false + noPreserveStateKey: '@!hmr', - // Prevent doing a full reload on next HMR update after fatal error - noReload: true, + // Prevent doing a full reload on next HMR update after fatal error + noReload: true, - // Try to recover after runtime errors in component init - optimistic: false, + // Try to recover after runtime errors in component init + optimistic: false, - // --- Advanced --- + // --- Advanced --- - // Prevent adding an HMR accept handler to components with - // accessors option to true, or to components with named exports - // (from