// // Copyright © 2020 Anticrm Platform Contributors. // // Licensed under the Eclipse Public License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. You may // obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // // See the License for the specific language governing permissions and // limitations under the License. // 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 { Configuration } = require('webpack') const mode = process.env.NODE_ENV || 'development' const prod = mode === 'production' 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 { EsbuildPlugin } = require('esbuild-loader') const doValidate = !prod || (process.env.DO_VALIDATE === 'true') const useCache = process.env.USE_CACHE === 'true' /** * @type {Configuration} */ module.exports = [ { mode: dev ? 'development' : mode, entry: { serviceWorker: '@hcengineering/notification/src/serviceWorker.ts' }, module: { rules: [ { test: /\.ts$/, exclude: /(node_modules|\.webpack)/, use: { loader: 'esbuild-loader', options: { target: 'es2021', keepNames: true, minify: prod, sourcemap: !prod } } } ] }, output: { path: __dirname + '/dist', filename: '[name].js', chunkFilename: '[name].js', publicPath: '/', pathinfo: false }, resolve: { extensions: ['.ts', '.js'], conditionNames: ['svelte', 'browser', 'import'] } }, { 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-/, }, /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: { cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all' } } } } : { minimize: false, mangleExports: false, usedExports: false, splitChunks: { cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name: 'vendors', chunks: 'all' } } } }, module: { rules: [ { test: /\.ts?$/, loader: 'esbuild-loader', options: { 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', // 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, // --- Advanced --- // Prevent adding an HMR accept handler to components with // accessors option to true, or to components with named exports // (from