68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { defineConfig } from "@tarojs/cli";
|
|
import path from "node:path";
|
|
import fs from "node:fs";
|
|
|
|
const root = path.resolve(__dirname, "../../..");
|
|
const key = process.env.TEMPLATE_KEY || "acheng-campus-food";
|
|
const templates = fs
|
|
.readdirSync(path.join(root, "packages"))
|
|
.filter(
|
|
(directory) =>
|
|
directory.startsWith("template-") &&
|
|
fs.existsSync(path.join(root, "packages", directory, "taro/index.tsx")) &&
|
|
fs.existsSync(path.join(root, "packages", directory, "template.json")),
|
|
)
|
|
.map((directory) => directory.slice("template-".length));
|
|
if (!templates.includes(key)) throw new Error(`Unsupported Taro template: ${key}`);
|
|
const template = path.join(root, "packages", `template-${key}`);
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(template, "template.json"), "utf8")) as {
|
|
packageKey: string;
|
|
defaultBrandSlug?: string;
|
|
};
|
|
if (manifest.packageKey !== key) throw new Error(`Template key mismatch: ${key}`);
|
|
const brand = process.env.BRAND_SLUG || manifest.defaultBrandSlug || "default-brand";
|
|
fs.cpSync(path.join(template, "miniapp/assets"), path.resolve(__dirname, "../src/assets"), {
|
|
recursive: true,
|
|
});
|
|
export default defineConfig({
|
|
projectName: "personal-brand-taro",
|
|
date: "2026-10-08",
|
|
designWidth: 750,
|
|
deviceRatio: { 750: 1 },
|
|
sourceRoot: "src",
|
|
outputRoot: `dist/${key}/${process.env.TARO_ENV || "weapp"}`,
|
|
framework: "react",
|
|
compiler: { type: "vite" },
|
|
plugins: [],
|
|
alias: { "@template": path.join(template, "taro") },
|
|
defineConstants: {
|
|
TEMPLATE_KEY: JSON.stringify(key),
|
|
BRAND_SLUG: JSON.stringify(brand),
|
|
API_BASE_URL: JSON.stringify(process.env.API_BASE_URL || "http://localhost:3001"),
|
|
TEMPLATE_MANIFEST: JSON.stringify(manifest),
|
|
},
|
|
copy: {
|
|
options: {},
|
|
patterns: [
|
|
...(process.env.TARO_ENV === "weapp"
|
|
? [
|
|
{
|
|
from: path.resolve(__dirname, "../project.config.json"),
|
|
to: `dist/${key}/weapp/project.config.json`,
|
|
},
|
|
]
|
|
: []),
|
|
{
|
|
from: path.join(template, "miniapp/assets"),
|
|
to: `dist/${key}/${process.env.TARO_ENV || "weapp"}/assets`,
|
|
},
|
|
],
|
|
},
|
|
mini: {},
|
|
h5: {
|
|
publicPath: "/",
|
|
router: { mode: "hash" },
|
|
devServer: { host: "0.0.0.0", port: Number(process.env.PREVIEW_PORT || 3002) },
|
|
},
|
|
});
|