// // 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 MiniCssExtractPlugin = require('mini-css-extract-plugin') const Dotenv = require('dotenv-webpack') const path = require('path') const autoprefixer = require('autoprefixer') const CompressionPlugin = require('compression-webpack-plugin') const DefinePlugin = require('webpack').DefinePlugin const { resolve } = require('path') 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 dev = (process.env.CLIENT_TYPE ?? '') === 'dev' || devServer || devProduction const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); /** * @type {Configuration} */ module.exports = { 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'), '@hcengineering/platform-rig/profiles/ui/svelte': path.resolve('./node_modules', 'svelte'), }, fallback: { crypto: false }, extensions: ['.mjs', '.js', '.svelte', '.ts'], mainFields: ['svelte', 'browser', 'module', 'main'] }, output: { path: __dirname + '/dist', filename: '[name].[contenthash].js', chunkFilename: '[name].[contenthash].js', publicPath: '/', pathinfo: false }, optimization: { minimize: prod }, module: { rules: [ { test: /\.ts?$/, loader:'ts-loader', options: { transpileOnly: 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: !prod, }), 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