2022-09-20 17:39:49 +00:00
|
|
|
import path from 'path';
|
|
|
|
import { Configuration } from 'webpack';
|
2022-10-04 16:00:37 +00:00
|
|
|
import CopyPlugin from 'copy-webpack-plugin';
|
2024-09-17 13:14:43 +00:00
|
|
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
|
|
import { version } from './package.json';
|
2022-04-21 14:52:54 +00:00
|
|
|
|
|
|
|
const config: Configuration = {
|
2022-09-20 17:39:49 +00:00
|
|
|
entry: './src/index.js',
|
2022-04-21 14:52:54 +00:00
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(ts|js)x?$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: {
|
2022-09-20 17:39:49 +00:00
|
|
|
loader: 'babel-loader',
|
2022-04-21 14:52:54 +00:00
|
|
|
options: {
|
2022-09-20 17:39:49 +00:00
|
|
|
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
|
2022-04-21 14:52:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2023-12-02 11:31:21 +00:00
|
|
|
experiments: { asyncWebAssembly: true },
|
2022-04-21 14:52:54 +00:00
|
|
|
resolve: {
|
2022-09-20 17:39:49 +00:00
|
|
|
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
2022-09-28 13:49:07 +00:00
|
|
|
},
|
2022-09-28 12:08:16 +00:00
|
|
|
};
|
|
|
|
|
2024-09-17 13:14:43 +00:00
|
|
|
const configNode: Configuration = {
|
2022-09-28 12:08:16 +00:00
|
|
|
...config,
|
2022-04-21 14:52:54 +00:00
|
|
|
output: {
|
2022-09-20 17:39:49 +00:00
|
|
|
path: path.resolve(__dirname, 'static/frontend'),
|
2024-09-17 13:14:43 +00:00
|
|
|
filename: `main.v${version}.[contenthash].js`,
|
|
|
|
clean: true,
|
2024-09-17 14:35:43 +00:00
|
|
|
publicPath: './static/frontend/',
|
2022-04-21 14:52:54 +00:00
|
|
|
},
|
2024-09-17 13:14:43 +00:00
|
|
|
plugins: [
|
2024-09-18 06:37:37 +00:00
|
|
|
// Django HTML
|
2024-09-17 13:14:43 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2024-09-18 06:37:37 +00:00
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: false,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, 'templates/frontend/basic.html'),
|
2024-09-17 13:14:43 +00:00
|
|
|
inject: 'body',
|
2024-09-18 06:37:37 +00:00
|
|
|
robosatsSettings: 'web-basic',
|
2024-09-17 13:14:43 +00:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
2024-09-18 06:37:37 +00:00
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: true,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, 'templates/frontend/pro.html'),
|
2024-09-17 13:14:43 +00:00
|
|
|
inject: 'body',
|
2024-09-18 06:37:37 +00:00
|
|
|
robosatsSettings: 'web-pro',
|
2024-09-17 13:14:43 +00:00
|
|
|
}),
|
2024-09-18 06:37:37 +00:00
|
|
|
// Node App HTML
|
2024-09-17 13:14:43 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2024-09-18 06:37:37 +00:00
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: false,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, '../nodeapp/basic.html'),
|
2024-09-17 13:14:43 +00:00
|
|
|
inject: 'body',
|
2024-09-18 06:37:37 +00:00
|
|
|
robosatsSettings: 'selfhosted-basic',
|
2024-09-17 13:14:43 +00:00
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({
|
2024-09-18 06:37:37 +00:00
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: true,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, '../nodeapp/pro.html'),
|
2024-09-17 13:14:43 +00:00
|
|
|
inject: 'body',
|
2024-09-18 06:37:37 +00:00
|
|
|
robosatsSettings: 'selfhosted-pro',
|
|
|
|
}),
|
|
|
|
// Desktop App HTML
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: false,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, '../desktopApp/index.html'),
|
|
|
|
inject: 'body',
|
|
|
|
robosatsSettings: 'desktop-basic',
|
|
|
|
}),
|
|
|
|
// Web App HTML
|
2024-09-18 06:52:08 +00:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: false,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, '../web/basic.html'),
|
|
|
|
inject: 'body',
|
|
|
|
robosatsSettings: 'web-basic',
|
2024-09-17 13:14:43 +00:00
|
|
|
}),
|
2024-09-18 06:52:08 +00:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: true,
|
|
|
|
},
|
|
|
|
filename: path.resolve(__dirname, '../web/pro.html'),
|
|
|
|
inject: 'body',
|
|
|
|
robosatsSettings: 'web-pro',
|
2024-09-18 06:37:37 +00:00
|
|
|
}),
|
|
|
|
// Static files
|
2024-09-17 13:14:43 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, 'static'),
|
|
|
|
to: path.resolve(__dirname, '../nodeapp/static'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, 'static'),
|
|
|
|
to: path.resolve(__dirname, '../web/static'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, 'static'),
|
|
|
|
to: path.resolve(__dirname, '../desktopApp/static'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
2022-04-21 14:52:54 +00:00
|
|
|
};
|
|
|
|
|
2023-05-29 15:58:12 +00:00
|
|
|
const configMobile: 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/Native.js'),
|
|
|
|
async: true,
|
|
|
|
},
|
|
|
|
},
|
2023-10-16 19:32:00 +00:00
|
|
|
{
|
|
|
|
test: path.resolve(__dirname, 'src/geo/Web.js'),
|
|
|
|
loader: 'file-replace-loader',
|
|
|
|
options: {
|
|
|
|
condition: 'if-replacement-exists',
|
|
|
|
replacement: path.resolve(__dirname, 'src/geo/Native.js'),
|
|
|
|
async: true,
|
|
|
|
},
|
|
|
|
},
|
2024-04-30 14:01:54 +00:00
|
|
|
{
|
|
|
|
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/Native.ts'),
|
|
|
|
async: true,
|
|
|
|
},
|
|
|
|
},
|
2023-05-29 15:58:12 +00:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
plugins: [
|
2024-09-17 13:14:43 +00:00
|
|
|
new HtmlWebpackPlugin({
|
2024-09-18 06:37:37 +00:00
|
|
|
template: path.resolve(__dirname, 'templates/frontend/index.ejs'),
|
|
|
|
templateParameters: {
|
|
|
|
pro: false,
|
|
|
|
},
|
2024-09-17 13:14:43 +00:00
|
|
|
filename: path.resolve(__dirname, '../mobile/html/Web.bundle/index.html'),
|
|
|
|
inject: 'body',
|
2024-09-18 06:37:37 +00:00
|
|
|
robosatsSettings: 'mobile-basic',
|
2024-09-17 13:14:43 +00:00
|
|
|
}),
|
2023-05-29 15:58:12 +00:00
|
|
|
new CopyPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: path.resolve(__dirname, 'static/css'),
|
2024-09-17 13:14:43 +00:00
|
|
|
to: path.resolve(__dirname, '../mobile/html/Web.bundle/static'),
|
2024-04-30 20:02:54 +00:00
|
|
|
},
|
2023-05-29 15:58:12 +00:00
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
output: {
|
2024-09-17 13:14:43 +00:00
|
|
|
path: path.resolve(__dirname, '../mobile/html/Web.bundle/static/frontend'),
|
|
|
|
filename: `main.v${version}.[contenthash].js`,
|
|
|
|
clean: true,
|
2024-09-17 14:35:43 +00:00
|
|
|
publicPath: './static/frontend/',
|
2022-10-20 18:06:16 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2024-09-18 06:37:37 +00:00
|
|
|
export default [configNode, configMobile];
|