// // Copyright © 2023 Hardcore Engineering Inc. // 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 CopyPlugin = require('copy-webpack-plugin') const mode = process.env.NODE_ENV || 'development' const prod = mode === 'production' const dev = (process.env.CLIENT_TYPE ?? '') === 'dev' || mode === 'development' const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin') console.log('mode', mode) const { EsbuildPlugin } = require('esbuild-loader') const doValidate = !prod || (process.env.DO_VALIDATE === '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'] } }, { mode: dev ? 'development' : mode, entry: { electron: './src/main/start.ts', preload: './src/ui/preload.ts' }, target: 'electron-main', plugins: [ ...(doValidate ? [new ForkTsCheckerWebpackPlugin()] : []), new Dotenv({ path: prod ? '.env' : '.env-dev' }), new DefinePlugin({ 'process.env.MODEL_VERSION': JSON.stringify(process.env.MODEL_VERSION) }) ], module: { rules: [ // Add support for native node modules { // We're specifying native_modules in the test because the asset relocator loader generates a // "fake" .node file which is really a cjs file. test: /native_modules[/\\].+\.node$/, use: 'node-loader' }, { test: /[/\\]node_modules[/\\].+\.(m?js|node)$/, parser: { amd: false }, use: { loader: '@vercel/webpack-asset-relocator-loader', options: { outputAssetBase: 'native_modules' } } }, { test: /\.ts$/, exclude: /(node_modules|\.webpack)/, use: { loader: 'esbuild-loader', options: { target: 'es2021', keepNames: true, minify: !prod, sourcemap: !prod } } } ] }, output: { globalObject: 'this', path: path.join(__dirname, '/dist/main/'), publicPath: '', clean: true }, resolve: { extensions: ['.ts', '.js'], conditionNames: ['svelte', 'browser', 'import'] } }, // ------ UI Part -------------------------- { entry: { bundle: ['@hcengineering/theme/styles/global.scss', ...['./src/ui/index.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, path: false, fs: false }, extensions: ['.mjs', '.js', '.svelte', '.ts'], conditionNames: ['svelte', 'browser', 'import'] }, output: { path: path.join(__dirname, '/dist/ui/'), filename: 'bundle.js', publicPath: '', chunkFormat: false, clean: true }, optimization: prod ? { minimize: true, minimizer: [ new EsbuildPlugin({ target: 'es2021', keepNames: true, minify: !prod, sourcemap: !prod }) ] } : {}, module: { rules: [ { test: /\.ts?$/, loader: 'esbuild-loader', options: { target: 'es2021', keepNames: true, minify: !prod, sourcemap: !prod }, exclude: /node_modules/ }, { test: /\.svelte$/, use: { loader: 'svelte-loader', options: { compilerOptions: { dev }, emitCss: true, hotReload: dev, preprocess: require('svelte-preprocess')({ postcss: true, sourceMap: dev }), 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