From 1ab3b5fc763e31c6fe6dbf90aaa63d138bf47fa3 Mon Sep 17 00:00:00 2001 From: ali asaria Date: Wed, 19 Mar 2025 14:22:41 -0400 Subject: [PATCH] you can now build the cloud version --- .erb/configs/webpack.config.cloud.prod.ts | 144 ++++++++++++++++++++++ .erb/configs/webpack.paths.ts | 2 + .gitignore | 1 + package.json | 1 + scripts/server.js | 2 +- 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 .erb/configs/webpack.config.cloud.prod.ts diff --git a/.erb/configs/webpack.config.cloud.prod.ts b/.erb/configs/webpack.config.cloud.prod.ts new file mode 100644 index 0000000..94d86ec --- /dev/null +++ b/.erb/configs/webpack.config.cloud.prod.ts @@ -0,0 +1,144 @@ +/** + * Build config for electron renderer process + */ + +import path from 'path'; +import webpack from 'webpack'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import MiniCssExtractPlugin from 'mini-css-extract-plugin'; +import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; +import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; +import { merge } from 'webpack-merge'; +import TerserPlugin from 'terser-webpack-plugin'; +import baseConfig from './webpack.config.base'; +import webpackPaths from './webpack.paths'; +import checkNodeEnv from '../scripts/check-node-env'; +import deleteSourceMaps from '../scripts/delete-source-maps'; + +checkNodeEnv('production'); +deleteSourceMaps(); + +const configuration: webpack.Configuration = { + devtool: 'source-map', + + mode: 'production', + + target: ['web', 'electron-renderer'], + + entry: [ + path.join(webpackPaths.srcMainPath, 'preload-cloud.ts'), + path.join(webpackPaths.srcRendererPath, 'index.tsx'), + ], + + output: { + path: webpackPaths.distCloudPath, + publicPath: './', + filename: 'renderer.js', + library: { + type: 'umd', + }, + }, + + module: { + rules: [ + { + test: /\.s?(a|c)ss$/, + use: [ + MiniCssExtractPlugin.loader, + { + loader: 'css-loader', + options: { + modules: true, + sourceMap: true, + importLoaders: 1, + }, + }, + 'sass-loader', + ], + include: /\.module\.s?(c|a)ss$/, + }, + { + test: /\.s?(a|c)ss$/, + use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'], + exclude: /\.module\.s?(c|a)ss$/, + }, + // Fonts + { + test: /\.(woff|woff2|eot|ttf|otf)$/i, + type: 'asset/resource', + }, + // Images + { + test: /\.(png|jpg|jpeg|gif)$/i, + type: 'asset/resource', + }, + // SVG + { + test: /\.svg$/, + use: [ + { + loader: '@svgr/webpack', + options: { + prettier: false, + svgo: false, + svgoConfig: { + plugins: [{ removeViewBox: false }], + }, + titleProp: true, + ref: true, + }, + }, + 'file-loader', + ], + }, + ], + }, + + optimization: { + minimize: true, + minimizer: [new TerserPlugin(), new CssMinimizerPlugin()], + }, + + plugins: [ + /** + * Create global constants which can be configured at compile time. + * + * Useful for allowing different behaviour between development builds and + * release builds + * + * NODE_ENV should be production so that modules do not perform certain + * development checks + */ + new webpack.EnvironmentPlugin({ + NODE_ENV: 'production', + DEBUG_PROD: false, + }), + + new MiniCssExtractPlugin({ + filename: 'style.css', + }), + + new BundleAnalyzerPlugin({ + analyzerMode: process.env.ANALYZE === 'true' ? 'server' : 'disabled', + analyzerPort: 8889, + }), + + new HtmlWebpackPlugin({ + filename: 'index.html', + template: path.join(webpackPaths.srcRendererPath, 'index.ejs'), + minify: { + collapseWhitespace: true, + removeAttributeQuotes: true, + removeComments: true, + }, + isBrowser: false, + isDevelopment: false, + }), + + new webpack.DefinePlugin({ + 'process.type': '"renderer"', + }), + ], +}; + +export default merge(baseConfig, configuration); diff --git a/.erb/configs/webpack.paths.ts b/.erb/configs/webpack.paths.ts index e5ba573..43038f5 100644 --- a/.erb/configs/webpack.paths.ts +++ b/.erb/configs/webpack.paths.ts @@ -17,6 +17,7 @@ const srcNodeModulesPath = path.join(srcPath, 'node_modules'); const distPath = path.join(appPath, 'dist'); const distMainPath = path.join(distPath, 'main'); const distRendererPath = path.join(distPath, 'renderer'); +const distCloudPath = path.join(releasePath, 'cloud'); const buildPath = path.join(releasePath, 'build'); @@ -34,5 +35,6 @@ export default { distPath, distMainPath, distRendererPath, + distCloudPath, buildPath, }; diff --git a/.gitignore b/.gitignore index da13430..4212706 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ node_modules release/app/dist release/build +release/cloud/* .erb/dll .idea diff --git a/package.json b/package.json index 791fa23..cc63cc8 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "build": "concurrently \"npm run build:main\" \"npm run build:renderer\"", "build:main": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.main.prod.ts", "build:renderer": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.prod.ts", + "build:cloud": "cross-env NODE_ENV=production TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.cloud.prod.ts", "postinstall": "ts-node .erb/scripts/check-native-dep.js && electron-builder install-app-deps && cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.renderer.dev.dll.ts", "lint": "cross-env NODE_ENV=development eslint . --ext .js,.jsx,.ts,.tsx", "package": "ts-node ./.erb/scripts/clean.js dist && npm run build && electron-builder build --publish never", diff --git a/scripts/server.js b/scripts/server.js index be8b858..f6ac8b8 100644 --- a/scripts/server.js +++ b/scripts/server.js @@ -7,7 +7,7 @@ const url = require('url'); const PORT = 4567; // Directory containing your HTML files -const DIRECTORY = './release/app/dist/renderer'; // Change this to your directory path if needed +const DIRECTORY = './release/cloud'; // Change this to your directory path if needed // Create the HTTP server const server = http.createServer((req, res) => {