From 562cec764c6755eb075d484377046f794096eaac Mon Sep 17 00:00:00 2001 From: koalasat Date: Sun, 20 Jul 2025 14:44:43 +0200 Subject: [PATCH] Fix webview --- frontend/webpack.config.ts | 405 +++++++++++++++++++------------------ 1 file changed, 207 insertions(+), 198 deletions(-) diff --git a/frontend/webpack.config.ts b/frontend/webpack.config.ts index 24d4e3a6..659e1424 100644 --- a/frontend/webpack.config.ts +++ b/frontend/webpack.config.ts @@ -34,216 +34,225 @@ const config: Configuration = { }, }; -const configNode: Configuration = { - ...config, - output: { - path: path.resolve(__dirname, 'static/frontend'), - filename: `main.v${version}.[contenthash].js`, - clean: true, - publicPath: '/static/frontend/', - }, - plugins: [ - // Django - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: false, - mobile: false, - }, - filename: path.resolve(__dirname, 'templates/frontend/basic.html'), - inject: 'body', - robosatsSettings: 'web-basic', - basePath: '/', - }), - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: true, - mobile: false, - }, - filename: path.resolve(__dirname, 'templates/frontend/pro.html'), - inject: 'body', - robosatsSettings: 'web-pro', - basePath: '/', - }), - // Node App - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: false, - mobile: false, - }, - filename: path.resolve(__dirname, '../nodeapp/basic.html'), - inject: 'body', - robosatsSettings: 'selfhosted-basic', - basePath: '/', - }), - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: true, - mobile: false, - }, - filename: path.resolve(__dirname, '../nodeapp/pro.html'), - inject: 'body', - robosatsSettings: 'selfhosted-pro', - basePath: '/', - }), - new CopyWebpackPlugin({ - patterns: [ - { - from: path.resolve(__dirname, 'static'), - to: path.resolve(__dirname, '../nodeapp/static'), +const configNode = (env: any, argv: { mode: string }): Configuration => { + return { + ...config, + output: { + path: path.resolve(__dirname, 'static/frontend'), + filename: + argv.mode === 'production' ? `main.v${version}.[contenthash].js` : `main.v${version}.js`, + clean: true, + publicPath: '/static/frontend/', + }, + plugins: [ + // Django + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: false, + mobile: false, }, - ], - }), - // Desktop App - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: false, - mobile: false, - }, - filename: path.resolve(__dirname, '../desktopApp/index.html'), - inject: 'body', - robosatsSettings: 'desktop-basic', - basePath: '/', - }), - new CopyWebpackPlugin({ - patterns: [ - { - from: path.resolve(__dirname, 'static'), - to: path.resolve(__dirname, '../desktopApp/static'), + filename: path.resolve(__dirname, 'templates/frontend/basic.html'), + inject: 'body', + robosatsSettings: 'web-basic', + basePath: '/', + }), + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: true, + mobile: false, }, - ], - }), - // Web App - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: false, - mobile: false, - }, - filename: path.resolve(__dirname, '../web/basic.html'), - inject: 'body', - robosatsSettings: 'web-basic', - basePath: '/', - }), - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: true, - mobile: false, - }, - filename: path.resolve(__dirname, '../web/pro.html'), - inject: 'body', - robosatsSettings: 'web-pro', - basePath: '/', - }), - new CopyWebpackPlugin({ - patterns: [ - { - from: path.resolve(__dirname, 'static'), - to: path.resolve(__dirname, '../web/static'), + filename: path.resolve(__dirname, 'templates/frontend/pro.html'), + inject: 'body', + robosatsSettings: 'web-pro', + basePath: '/', + }), + // Node App + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: false, + mobile: false, }, - ], - }), - ], + filename: path.resolve(__dirname, '../nodeapp/basic.html'), + inject: 'body', + robosatsSettings: 'selfhosted-basic', + basePath: '/', + }), + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: true, + mobile: false, + }, + filename: path.resolve(__dirname, '../nodeapp/pro.html'), + inject: 'body', + robosatsSettings: 'selfhosted-pro', + basePath: '/', + }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'static'), + to: path.resolve(__dirname, '../nodeapp/static'), + }, + ], + }), + // Desktop App + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: false, + mobile: false, + }, + filename: path.resolve(__dirname, '../desktopApp/index.html'), + inject: 'body', + robosatsSettings: 'desktop-basic', + basePath: '/', + }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'static'), + to: path.resolve(__dirname, '../desktopApp/static'), + }, + ], + }), + // Web App + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: false, + mobile: false, + }, + filename: path.resolve(__dirname, '../web/basic.html'), + inject: 'body', + robosatsSettings: 'web-basic', + basePath: '/', + }), + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: true, + mobile: false, + }, + filename: path.resolve(__dirname, '../web/pro.html'), + inject: 'body', + robosatsSettings: 'web-pro', + basePath: '/', + }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'static'), + to: path.resolve(__dirname, '../web/static'), + }, + ], + }), + ], + }; }; -const configAndroid: Configuration = { - ...config, - module: { - ...config.module, - rules: [ - ...(config?.module?.rules || []), - { - test: path.resolve(__dirname, 'src/i18n/Web.js'), - loader: 'file-replace-loader', - options: { - condition: 'if-replacement-exists', - replacement: path.resolve(__dirname, 'src/i18n/Mobile.js'), - async: true, - }, - }, - { - test: path.resolve(__dirname, 'src/geo/Web.js'), - loader: 'file-replace-loader', - options: { - condition: 'if-replacement-exists', - replacement: path.resolve(__dirname, 'src/geo/Mobile.js'), - async: true, - }, - }, - { - test: path.resolve(__dirname, 'src/services/Roboidentities/Web.ts'), - loader: 'file-replace-loader', - options: { - condition: 'if-replacement-exists', - replacement: path.resolve(__dirname, 'src/services/Roboidentities/Android.ts'), - async: true, - }, - }, - { - test: path.resolve(__dirname, 'src/components/RobotAvatar/placeholder.json'), - loader: 'file-replace-loader', - options: { - condition: 'if-replacement-exists', - replacement: path.resolve( - __dirname, - 'src/components/RobotAvatar/placeholder_highres.json', - ), - async: true, - }, - }, - ], - }, - output: { - path: path.resolve(__dirname, '../android/app/src/main/assets/static/frontend'), - filename: `main.v${version}.[contenthash].js`, - clean: true, - publicPath: './static/frontend/', - }, - plugins: [ - new HtmlWebpackPlugin({ - template: path.resolve(__dirname, 'templates/frontend/index.ejs'), - templateParameters: { - pro: false, - mobile: true, - }, - filename: path.resolve(__dirname, '../android/app/src/main/assets/index.html'), - inject: 'body', - robosatsSettings: 'mobile-basic', - basePath: 'file:///android_asset/', - }), - new CopyWebpackPlugin({ - patterns: [ +const configAndroid = (env: any, argv: { mode: string }): Configuration => { + return { + ...config, + module: { + ...config.module, + rules: [ + ...(config?.module?.rules || []), { - from: path.resolve(__dirname, 'static/css'), - to: path.resolve(__dirname, '../android/app/src/main/assets/static/css'), - transform(content, path) { - if (path.endsWith('.css')) { - let cssContent = content.toString(); - cssContent = cssContent.replace( - /url\(\/static\/css\/fonts\/roboto/g, - 'url(file:///android_asset/static/css/fonts/roboto', - ); - return Buffer.from(cssContent); - } - return content; + test: path.resolve(__dirname, 'src/i18n/Web.js'), + loader: 'file-replace-loader', + options: { + condition: 'if-replacement-exists', + replacement: path.resolve(__dirname, 'src/i18n/Mobile.js'), + async: true, }, }, { - from: path.resolve(__dirname, 'static/assets/sounds'), - to: path.resolve(__dirname, '../android/app/src/main/assets/static/assets/sounds'), + test: path.resolve(__dirname, 'src/geo/Web.js'), + loader: 'file-replace-loader', + options: { + condition: 'if-replacement-exists', + replacement: path.resolve(__dirname, 'src/geo/Mobile.js'), + async: true, + }, }, { - from: path.resolve(__dirname, 'static/federation'), - to: path.resolve(__dirname, '../android/app/src/main/assets/static/assets/federation'), + test: path.resolve(__dirname, 'src/services/Roboidentities/Web.ts'), + loader: 'file-replace-loader', + options: { + condition: 'if-replacement-exists', + replacement: path.resolve(__dirname, 'src/services/Roboidentities/Android.ts'), + async: true, + }, + }, + { + test: path.resolve(__dirname, 'src/components/RobotAvatar/placeholder.json'), + loader: 'file-replace-loader', + options: { + condition: 'if-replacement-exists', + replacement: path.resolve( + __dirname, + 'src/components/RobotAvatar/placeholder_highres.json', + ), + async: true, + }, }, ], - }), - ], + }, + output: { + path: path.resolve(__dirname, '../android/app/src/main/assets/static/frontend'), + filename: + argv.mode === 'production' ? `main.v${version}.[contenthash].js` : `main.v${version}.js`, + clean: true, + publicPath: './static/frontend/', + }, + plugins: [ + new HtmlWebpackPlugin({ + template: path.resolve(__dirname, 'templates/frontend/index.ejs'), + templateParameters: { + pro: false, + mobile: true, + }, + filename: path.resolve(__dirname, '../android/app/src/main/assets/index.html'), + inject: 'body', + robosatsSettings: 'mobile-basic', + basePath: 'file:///android_asset/', + }), + new CopyWebpackPlugin({ + patterns: [ + { + from: path.resolve(__dirname, 'static/css'), + to: path.resolve(__dirname, '../android/app/src/main/assets/static/css'), + transform(content, path) { + if (path.endsWith('.css')) { + let cssContent = content.toString(); + cssContent = cssContent.replace( + /url\(\/static\/css\/fonts\/roboto/g, + 'url(file:///android_asset/static/css/fonts/roboto', + ); + return Buffer.from(cssContent); + } + return content; + }, + }, + { + from: path.resolve(__dirname, 'static/assets/sounds'), + to: path.resolve(__dirname, '../android/app/src/main/assets/static/assets/sounds'), + }, + { + from: path.resolve(__dirname, 'static/federation'), + to: path.resolve(__dirname, '../android/app/src/main/assets/static/assets/federation'), + }, + ], + }), + ], + }; }; -export default [configNode, configAndroid]; +export default (env: any, argv: { mode: string }) => [ + configNode(env, argv), + configAndroid(env, argv), +];