|
| 1 | +import { defineConfig } from '@rspack/cli'; |
| 2 | +import { rspack } from '@rspack/core'; |
| 3 | +import path from 'path'; |
| 4 | + |
| 5 | +const mode = process.env.NODE_ENV || 'development'; |
| 6 | +const prod = mode === 'production'; |
| 7 | + |
| 8 | +const clientType = process.env.CLIENT_TYPE || ''; |
| 9 | +const dev = mode === 'development' || clientType === 'dev'; |
| 10 | + |
| 11 | +const devProxy = [ |
| 12 | + { |
| 13 | + context: ['/account'], |
| 14 | + target: 'http://huly.local:3000', |
| 15 | + changeOrigin: true, |
| 16 | + pathRewrite: { '^/account': '' }, |
| 17 | + }, |
| 18 | + { |
| 19 | + context: ['/api/v1', '/files', '/import'], |
| 20 | + target: 'http://huly.local:8087', |
| 21 | + changeOrigin: true, |
| 22 | + }, |
| 23 | + { |
| 24 | + context: ['/rekoni/recognize'], |
| 25 | + target: 'http://huly.local:4004', |
| 26 | + changeOrigin: true, |
| 27 | + pathRewrite: { '^/rekoni/recognize': '/recognize' }, |
| 28 | + } |
| 29 | +]; |
| 30 | + |
| 31 | +const devProxyTest = [ |
| 32 | + { |
| 33 | + context: ['/account'], |
| 34 | + target: 'http://huly.local:3003', |
| 35 | + changeOrigin: true, |
| 36 | + pathRewrite: { '^/account': '' }, |
| 37 | + }, |
| 38 | + { |
| 39 | + context: ['/api/v1', '/files', '/import'], |
| 40 | + target: 'http://huly.local:8083', |
| 41 | + changeOrigin: true, |
| 42 | + }, |
| 43 | + { |
| 44 | + context: ['/rekoni/recognize'], |
| 45 | + target: 'http://huly.local:4004', |
| 46 | + changeOrigin: true, |
| 47 | + pathRewrite: { '^/rekoni/recognize': '/recognize' }, |
| 48 | + } |
| 49 | +]; |
| 50 | + |
| 51 | +const proxies: Record<string, any> = { |
| 52 | + 'dev-worker': devProxy, |
| 53 | + 'dev-worker-local': devProxy, |
| 54 | + 'dev-server': devProxy, |
| 55 | + 'dev-server-test': devProxyTest, |
| 56 | +}; |
| 57 | + |
| 58 | +export default defineConfig({ |
| 59 | + mode: prod ? 'production' : 'development', |
| 60 | + context: __dirname, |
| 61 | + entry: { |
| 62 | + main: [ |
| 63 | + '@hcengineering/theme/styles/global.scss', |
| 64 | + './src/eager-bundle.ts', |
| 65 | + dev && (clientType === 'dev-server' || clientType === 'dev') ? './src/main-dev.ts' : './src/main.ts' |
| 66 | + ], |
| 67 | + }, |
| 68 | + output: { |
| 69 | + path: path.resolve(__dirname, 'dist'), |
| 70 | + filename: '[name].[contenthash].js', |
| 71 | + publicPath: '/', |
| 72 | + clean: true, |
| 73 | + }, |
| 74 | + resolve: { |
| 75 | + extensions: ['.mjs', '.js', '.svelte', '.ts'], |
| 76 | + mainFields: ['svelte', 'browser', 'module', 'main'], |
| 77 | + conditionNames: ['svelte', 'browser', 'import'], |
| 78 | + alias: { |
| 79 | + '@hcengineering/platform-rig/profiles/ui/svelte$': path.resolve(__dirname, 'node_modules/svelte/src/runtime/index.js'), |
| 80 | + }, |
| 81 | + fallback: { |
| 82 | + crypto: false, |
| 83 | + fs: false, |
| 84 | + path: false, |
| 85 | + os: false, |
| 86 | + net: false, |
| 87 | + tls: false, |
| 88 | + child_process: false, |
| 89 | + http: false, |
| 90 | + https: false, |
| 91 | + stream: false, |
| 92 | + constants: false, |
| 93 | + dns: false, |
| 94 | + }, |
| 95 | + symlinks: true, |
| 96 | + }, |
| 97 | + module: { |
| 98 | + rules: [ |
| 99 | + { |
| 100 | + test: /\.svelte$/, |
| 101 | + use: [ |
| 102 | + { |
| 103 | + loader: 'svelte-loader', |
| 104 | + options: { |
| 105 | + preprocess: require('svelte-preprocess')({ |
| 106 | + postcss: true, |
| 107 | + scss: { |
| 108 | + silenceDeprecations: ['legacy-js-api'] |
| 109 | + } |
| 110 | + }), |
| 111 | + onwarn: (warning: any, handler: any) => { |
| 112 | + if (warning.code === 'css-unused-selector' || warning.code === 'a11y-missing-attribute') return; |
| 113 | + handler(warning); |
| 114 | + } |
| 115 | + }, |
| 116 | + }, |
| 117 | + ], |
| 118 | + }, |
| 119 | + { |
| 120 | + test: /\.ts$/, |
| 121 | + exclude: [/node_modules/], |
| 122 | + loader: 'builtin:swc-loader', |
| 123 | + options: { |
| 124 | + jsc: { |
| 125 | + parser: { |
| 126 | + syntax: 'typescript', |
| 127 | + }, |
| 128 | + preserveAllComments: true, |
| 129 | + }, |
| 130 | + }, |
| 131 | + type: 'javascript/auto', |
| 132 | + }, |
| 133 | + { |
| 134 | + test: /\.scss$/, |
| 135 | + use: [ |
| 136 | + 'style-loader', |
| 137 | + 'css-loader', |
| 138 | + { |
| 139 | + loader: 'sass-loader', |
| 140 | + options: { |
| 141 | + api: 'modern', |
| 142 | + sassOptions: { |
| 143 | + quietDeps: true, |
| 144 | + }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + ], |
| 148 | + type: 'javascript/auto', |
| 149 | + }, |
| 150 | + { |
| 151 | + test: /\.css$/, |
| 152 | + use: [ |
| 153 | + 'style-loader', |
| 154 | + 'css-loader', |
| 155 | + ], |
| 156 | + type: 'javascript/auto', |
| 157 | + }, |
| 158 | + { |
| 159 | + test: /\.(png|svg|jpg|webp|avif|ico|wav|mp3|ogg|aac|woff|woff2|ttf|otf)$/, |
| 160 | + type: 'asset/resource', |
| 161 | + }, |
| 162 | + ], |
| 163 | + }, |
| 164 | + optimization: { |
| 165 | + splitChunks: false, |
| 166 | + }, |
| 167 | + lazyCompilation: false, |
| 168 | + stats: 'errors-only', |
| 169 | + infrastructureLogging: { |
| 170 | + level: 'none', |
| 171 | + }, |
| 172 | + plugins: [ |
| 173 | + new rspack.HtmlRspackPlugin({ |
| 174 | + meta: { |
| 175 | + viewport: 'width=device-width, initial-scale=1.0', |
| 176 | + }, |
| 177 | + }), |
| 178 | + new rspack.DefinePlugin({ |
| 179 | + 'process.env.NODE_ENV': JSON.stringify(mode), |
| 180 | + 'process.env.CLIENT_TYPE': JSON.stringify(clientType), |
| 181 | + }), |
| 182 | + ], |
| 183 | + devServer: { |
| 184 | + port: 8080, |
| 185 | + host: '0.0.0.0', |
| 186 | + allowedHosts: 'all', |
| 187 | + historyApiFallback: { |
| 188 | + disableDotRule: true, |
| 189 | + }, |
| 190 | + devMiddleware: { |
| 191 | + publicPath: '/', |
| 192 | + }, |
| 193 | + client: { |
| 194 | + overlay: false, |
| 195 | + logging: 'none', |
| 196 | + }, |
| 197 | + proxy: proxies[clientType] || devProxy, |
| 198 | + static: { |
| 199 | + directory: path.resolve(__dirname, 'public'), |
| 200 | + publicPath: '/', |
| 201 | + }, |
| 202 | + hot: true, |
| 203 | + }, |
| 204 | + watchOptions: { |
| 205 | + ignored: /node_modules/, |
| 206 | + poll: 1000, |
| 207 | + }, |
| 208 | +}); |
0 commit comments