Files
SupplierSystem/webpack.config.js
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

200 lines
6.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (env = {}, argv = {}) => {
const isDev = argv.mode !== 'production';
const buildId = new Date().toISOString().replace(/[:.]/g, '-');
// 本地预览默认 HTTPS;`webpack serve --env nohttps` 或 DEV_HTTPS=0 回退 HTTP
const useDevHttps = process.env.DEV_HTTPS !== '0' && !env.nohttps;
return {
mode: isDev ? 'development' : 'production',
devtool: isDev ? 'source-map' : false,
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: isDev ? 'bundle.js' : 'bundle.[contenthash:8].js',
chunkFilename: isDev ? '[name].bundle.js' : '[name].bundle.[contenthash:8].js',
publicPath: '/',
clean: true,
},
optimization: {
splitChunks: isDev
? false
: {
chunks: 'all',
maxInitialRequests: 25,
cacheGroups: {
// initial only:避免懒路由依赖(framer-motion/jsbarcode)被抬进首包 vendors
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'initial',
priority: 10,
},
xlsx: {
test: /[\\/]node_modules[\\/]xlsx[\\/]/,
name: 'xlsx',
chunks: 'async',
priority: 20,
},
framerMotion: {
test: /[\\/]node_modules[\\/]framer-motion[\\/]/,
name: 'motion',
chunks: 'async',
priority: 20,
},
jsbarcode: {
test: /[\\/]node_modules[\\/]jsbarcode[\\/]/,
name: 'barcode',
chunks: 'async',
priority: 20,
},
},
},
runtimeChunk: isDev ? false : 'single',
},
performance: isDev
? false
: {
// xlsx 为按需加载的导入导出模块;主入口是包含 React 与基础样式的管理端壳。
// 预算按当前架构分别设置,仍会在体积继续明显增长时报警。
maxAssetSize: 450 * 1024,
maxEntrypointSize: 700 * 1024,
},
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: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
],
},
{
test: /\.(png|jpe?g|gif|webp|ico|svg)$/i,
type: 'asset',
// 方案 A:将小于 1MB 的图片资源内联为 dataURL,使 Webpack 产物和 Vite 产物在 OSS 上结构一致
// 消费端 HomeController 只需替换 link[href].css / script[src].js 即可预览
parser: { dataUrlCondition: { maxSize: 1024 * 1024 } }
},
{
test: /\.(woff2?|eot|ttf|otf)$/i,
type: 'asset/resource'
},
{
// 兜底规则:PDF、文档、音视频等所有其他文件一律输出为独立资源文件
exclude: /\.(js|jsx|ts|tsx|mjs|css|json|html)$/i,
type: 'asset/resource'
}
]
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.mjs', '.ts', '.tsx', '.js', '.jsx']
},
devServer: {
// 约束 A:沙箱只开放一个代理端口,所有 builder(webpack/vite/electron)统一 3015
port: 3015,
host: '0.0.0.0',
allowedHosts: 'all',
// 本地预览默认 HTTPS(自签证书需浏览器点「继续访问」)
server: useDevHttps ? 'https' : 'http',
client: {
// 允许局域网设备访问时 HMR WebSocket 正常连接(auto 适配 http/https → ws/wss)
webSocketURL: 'auto://0.0.0.0:0/ws',
},
static: {
directory: path.resolve(__dirname, 'public'),
},
historyApiFallback: {
index: '/index.html',
rewrites: [
{ from: /^\/_p\/\d+\//, to: '/index.html' }
]
},
proxy: [
{
context: ['/api'],
target: 'http://127.0.0.1:3001',
changeOrigin: true,
secure: false,
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
inject: 'body',
templateParameters: {
BUILD_ID: buildId,
// 开发:webpack HMR / 部分工具链会用到 eval;生产构建保持严格 CSP(与 nginx 一致)
CSP_SCRIPT_SRC: isDev ? "'self' 'unsafe-eval'" : "'self'",
},
}),
...(isDev ? [] : [new MiniCssExtractPlugin({ filename: 'styles.[contenthash:8].css' })]),
{
apply(compiler) {
compiler.hooks.afterEmit.tap('CopyPublicConfig', () => {
const fs = require('fs');
const from = path.resolve(__dirname, 'public/config.js');
const distDir = path.resolve(__dirname, 'dist');
const to = path.join(distDir, 'config.js');
fs.mkdirSync(distDir, { recursive: true });
const apiBase = " apiBase: '/api',";
const buildLine = ` buildId: '${buildId}',`;
if (fs.existsSync(from)) {
const base = fs.readFileSync(from, 'utf8');
const injected = base.includes('buildId:')
? base.replace(/buildId:\s*'[^']*',?/, buildLine)
: base.replace(apiBase, `${apiBase}\n${buildLine}`);
fs.writeFileSync(to, injected);
} else {
fs.writeFileSync(
to,
`window.__APP_CONFIG__ = window.__APP_CONFIG__ || {\n${apiBase}\n${buildLine}\n};\n`
);
}
fs.copyFileSync(
path.resolve(__dirname, 'public/bootstrap.js'),
path.resolve(__dirname, 'dist/bootstrap.js')
);
});
},
},
]
};
};