2026-05-26 05:15:10 +00:00
|
|
|
|
const path = require('path');
|
|
|
|
|
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
|
|
|
|
const webpack = require('webpack');
|
|
|
|
|
|
const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
|
|
|
2026-06-04 15:09:31 +00:00
|
|
|
|
// 端口从环境变量读取,默认 3015(沙箱固定端口)
|
|
|
|
|
|
const DEV_PORT = parseInt(process.env.DEV_PORT || '3015', 10);
|
|
|
|
|
|
|
2026-05-26 05:15:10 +00:00
|
|
|
|
module.exports = (env, argv) => {
|
|
|
|
|
|
const isDev = argv.mode !== 'production';
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
mode: isDev ? 'development' : 'production',
|
|
|
|
|
|
entry: './src/index.tsx',
|
|
|
|
|
|
output: {
|
|
|
|
|
|
path: path.resolve(__dirname, 'dist'),
|
2026-05-27 03:17:46 +00:00
|
|
|
|
filename: '[name].js',
|
|
|
|
|
|
chunkFilename: '[name].chunk.js',
|
2026-05-26 05:15:10 +00:00
|
|
|
|
publicPath: '/',
|
|
|
|
|
|
clean: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
optimization: {
|
|
|
|
|
|
minimize: !isDev,
|
|
|
|
|
|
minimizer: [
|
|
|
|
|
|
new TerserPlugin({
|
|
|
|
|
|
terserOptions: {
|
|
|
|
|
|
compress: {
|
|
|
|
|
|
drop_console: true,
|
|
|
|
|
|
drop_debugger: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
format: {
|
|
|
|
|
|
comments: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
extractComments: false,
|
|
|
|
|
|
}),
|
|
|
|
|
|
],
|
|
|
|
|
|
splitChunks: {
|
|
|
|
|
|
chunks: 'all',
|
|
|
|
|
|
cacheGroups: {
|
|
|
|
|
|
vendor: {
|
|
|
|
|
|
test: /[\\/]node_modules[\\/]/,
|
|
|
|
|
|
name: 'vendors',
|
|
|
|
|
|
chunks: 'all',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
module: {
|
|
|
|
|
|
rules: [
|
|
|
|
|
|
{
|
|
|
|
|
|
test: /\.mjs$/,
|
|
|
|
|
|
include: /node_modules/,
|
|
|
|
|
|
type: 'javascript/auto',
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
fullySpecified: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
test: /\.(ts|tsx|js|jsx)$/,
|
|
|
|
|
|
exclude: /node_modules/,
|
|
|
|
|
|
use: {
|
|
|
|
|
|
loader: 'babel-loader',
|
|
|
|
|
|
options: {
|
|
|
|
|
|
presets: [
|
|
|
|
|
|
['@babel/preset-react', { runtime: 'automatic', development: isDev }],
|
|
|
|
|
|
'@babel/preset-env',
|
|
|
|
|
|
'@babel/preset-typescript'
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
test: /\.css$/,
|
|
|
|
|
|
use: ['style-loader', 'css-loader', 'postcss-loader']
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
test: /\.(png|jpe?g|gif|webp|svg)$/i,
|
|
|
|
|
|
type: 'asset',
|
|
|
|
|
|
parser: { dataUrlCondition: { maxSize: 1024 * 1024 } }
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
exclude: /\.(js|jsx|ts|tsx|mjs|css|json|html)$/i,
|
|
|
|
|
|
type: 'asset/resource'
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
extensions: ['.mjs', '.ts', '.tsx', '.js', '.jsx']
|
|
|
|
|
|
},
|
|
|
|
|
|
devServer: {
|
2026-06-04 15:09:31 +00:00
|
|
|
|
port: DEV_PORT,
|
2026-05-26 05:15:10 +00:00
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
|
allowedHosts: 'all',
|
|
|
|
|
|
hot: true,
|
|
|
|
|
|
historyApiFallback: true,
|
refactor: replace Supabase SDK with self-hosted REST API client layer
WHY: migrating from Supabase BaaS to self-hosted iloom backend
(Go microservices) deployed on K3s. Supabase client and realtime
subscriptions no longer applicable.
HOW:
- add src/api/ layer (client.ts, auth.ts, purchaser.ts, textile.ts,
washing.ts, websocket.ts) targeting iloom-gateway REST endpoints
- rewrite all hooks (usePlanData, useInventoryData, useDashboardData,
useRealtime, etc.) to use new API client instead of Supabase queries
- rewrite all page/component data fetching and mutations accordingly
- delete src/supabase/client.ts, remove @supabase/supabase-js dep
- add Dockerfile (multi-stage node build + nginx) and nginx.conf
with reverse proxy to iloom-gateway for /api/ and /ws/ routes
- adjust webpack.config.js for API_URL environment variable injection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-14 12:38:47 +08:00
|
|
|
|
proxy: [
|
|
|
|
|
|
{
|
|
|
|
|
|
context: ['/api', '/ws'],
|
|
|
|
|
|
target: `http://localhost:${process.env.GATEWAY_PORT || '8080'}`,
|
|
|
|
|
|
ws: true,
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2026-05-26 05:15:10 +00:00
|
|
|
|
},
|
|
|
|
|
|
plugins: [
|
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
|
|
template: './index.html',
|
|
|
|
|
|
inject: 'body',
|
|
|
|
|
|
}),
|
|
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(isDev ? 'development' : 'production'),
|
2026-06-04 15:09:31 +00:00
|
|
|
|
'__APP_ENV__': JSON.stringify(isDev ? 'development' : 'production'),
|
2026-05-26 05:15:10 +00:00
|
|
|
|
}),
|
|
|
|
|
|
],
|
|
|
|
|
|
};
|
|
|
|
|
|
};
|