1 Star 0 Fork 9

ForeverAct/Biomes

forked from Gitee 极速下载/Biomes 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
server.webpack.config.ts 3.20 KB
一键复制 编辑 原始数据 按行查看 历史
Nick Cooper 提交于 2023-08-11 15:35 . First commit
import fs from "fs/promises";
import path from "path";
import webpack from "webpack";
import nodeExternals from "webpack-node-externals";
const SERVERS = [
"anima",
"ask",
"backup",
"bob",
"chat",
["gaia-v2", "server/gaia_v2/main.ts"],
"gizmo",
"logic",
"map",
"newton",
"oob",
"sink",
"spawn",
"sync",
"task",
"trigger",
"web",
] as const;
function sourcePath(...parts: string[]) {
return path.resolve(__dirname, "src", ...parts);
}
function createEntryPoints() {
const entryPoints: Record<string, string> = {};
for (const config of SERVERS) {
const [name, entrypointPath] =
typeof config === "string"
? [config, `server/${config}/main.ts`]
: config;
entryPoints[name] = sourcePath(entrypointPath);
}
return entryPoints;
}
async function attemptBuildFromFile(...relativePath: string[]) {
try {
const buildId = (
await fs.readFile(path.join(__dirname, ...relativePath))
).toString();
if (buildId !== "local") {
return buildId;
}
} catch (error) {
// Pass through
}
}
async function getBuildId() {
return (
(await attemptBuildFromFile(".next", "BUILD_ID")) ??
(await attemptBuildFromFile("BUILD_ID")) ??
"unknown"
);
}
async function createWebpackConfig() {
return <webpack.Configuration>{
mode: "production",
// Configure NodeJS environment settings.
externalsPresets: { node: true },
node: {
global: false,
__filename: true,
__dirname: true,
},
target: "node",
// Don't include node_modules, it'll be part of the dist.
externals: [nodeExternals()],
entry: createEntryPoints(),
devtool: "inline-source-map",
context: __dirname,
cache: {
type: "filesystem",
},
optimization: {
// We don't need minimization on the server, if anything it just makes
// source maps more confusing.
minimize: false,
},
// Configure some expected defines.
plugins: [
new webpack.DefinePlugin({
"process.env.IS_SERVER": JSON.stringify(true),
"process.env.BUILD_ID": JSON.stringify(await getBuildId()),
"process.env.BUILD_TIMESTAMP": JSON.stringify(Date.now()),
}),
],
module: {
rules: [
{
test: /\.ts$/,
use: [
"thread-loader",
{
loader: "ts-loader",
options: {
configFile: "tsconfig.server.json",
transpileOnly: true,
happyPackMode: true,
},
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".ts", "..."],
alias: {
"@/galois": sourcePath("galois/js/"),
"@/wasm/cayley": path.resolve(
__dirname,
"src/gen/cayley/impl/wasm_bundler"
),
"@": sourcePath(),
},
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
},
experiments: {
futureDefaults: true,
},
// Skip all Webpack warnings around entrypoint size.
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};
}
export default createWebpackConfig();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/ForeverAct/Biomes.git
[email protected]:ForeverAct/Biomes.git
ForeverAct
Biomes
Biomes
main

搜索帮助