- src/config.js 的 API_KEY 改为从构建时环境变量 TINODE_API_KEY 注入, 不再依赖官方demo默认值;未设置时保留原demo key作为本地快速测试的兜底 - webpack.config.js 新增 DefinePlugin 完成注入,并自动加载(gitignored的) .env.local,开发者本地调试不需要每次手动export - 新增 Dockerfile(node构建+nginx serve) 和 docker/nginx.conf - 新增 .gitea/workflows/deploy.yml:手动触发的蓝绿发布流程
85 lines
2.5 KiB
JavaScript
85 lines
2.5 KiB
JavaScript
const CopyPlugin = require('copy-webpack-plugin');
|
|
const webpack = require('webpack');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Load developer-local overrides (gitignored) so `npm run build` picks up
|
|
// TINODE_API_KEY etc. without having to export them by hand every time.
|
|
const envLocalPath = path.resolve(__dirname, '.env.local');
|
|
if (fs.existsSync(envLocalPath)) {
|
|
for (const line of fs.readFileSync(envLocalPath, 'utf8').split('\n')) {
|
|
const match = line.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)\s*$/);
|
|
if (match) {
|
|
process.env[match[1]] = process.env[match[1]] || match[2];
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = (env, argv) => {
|
|
const mode = argv.mode === 'production' ? 'prod' : 'dev';
|
|
const maxAssetSize = mode === 'prod' ? 360000 : 1512000;
|
|
return {
|
|
entry: {
|
|
index: path.resolve(__dirname, 'src/index.js'),
|
|
},
|
|
devtool: 'source-map',
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.jsx?$/,
|
|
use: [
|
|
{
|
|
loader: 'babel-loader',
|
|
options: {
|
|
envName: mode === 'prod' ? 'production' : 'development',
|
|
},
|
|
},
|
|
],
|
|
exclude: /node_modules/,
|
|
},
|
|
],
|
|
},
|
|
output: {
|
|
path: path.resolve(__dirname, 'umd'),
|
|
filename: `[name].${mode}.js`,
|
|
publicPath: '/umd/'
|
|
},
|
|
optimization: {
|
|
minimize: (mode === 'prod'),
|
|
minimizer: ['...']
|
|
},
|
|
performance: {
|
|
maxEntrypointSize: maxAssetSize,
|
|
maxAssetSize: maxAssetSize,
|
|
assetFilter: function(assetFilename) {
|
|
// Exclude all sourcemaps
|
|
if (/\.map$/.test(assetFilename)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
},
|
|
plugins: [
|
|
new CopyPlugin({
|
|
patterns: [
|
|
{ from: `node_modules/tinode-sdk/umd/tinode.${mode}.js`, to: `tinode.${mode}.js` },
|
|
{ from: `node_modules/tinode-sdk/umd/tinode.${mode}.js.map`, to: `tinode.${mode}.js.map` },
|
|
],
|
|
}),
|
|
// Bakes TINODE_API_KEY (from the environment or .env.local) into the bundle at build
|
|
// time. See src/config.js for the fallback used when it's not set.
|
|
new webpack.DefinePlugin({
|
|
'process.env.TINODE_API_KEY': JSON.stringify(process.env.TINODE_API_KEY || ''),
|
|
}),
|
|
],
|
|
externals: {
|
|
'livekit-client': 'LivekitClient',
|
|
'qrcodejs': 'QRCode',
|
|
'react': 'React',
|
|
'react-dom': 'ReactDOM',
|
|
'react-intl': 'ReactIntl',
|
|
'tinode-sdk': 'tinode',
|
|
},
|
|
};
|
|
}
|