UNPKG

beesbuild

Version:

构建工具链

115 lines (114 loc) 3.46 kB
import path from "path"; import Module from "node:module"; import { defu } from "defu"; import { mergeWith, omit, uniqueId } from "lodash-unified"; import { createHooks } from "hookable"; import { getPackageManifest, target, tryRequire } from "@beesbuild/utils"; function beesBuildOption() { return { name: "default", rootDir: process.cwd(), entries: [], clean: false, declaration: false, sourcemap: false, minify: false, stub: false, outDir: ".", externals: [...Module.builtinModules, ...Module.builtinModules.map((m) => `node:${m}`)], dependencies: [], devDependencies: [], peerDependencies: [], alias: {}, replace: {}, stubOptions: { jiti: { esmResolve: true, interopDefault: true, alias: {} } }, failOnWarn: true, rollup: { vue: false, emitCJS: true, cjsBridge: true, inlineDependencies: false, preserveDynamicImports: true, // Plugins replace: { preventAssignment: true }, alias: {}, resolve: { preferBuiltins: true }, json: { preferConst: true }, commonjs: { ignoreTryCatch: true }, esbuild: { target, minify: false, drop: ["console", "debugger"] }, dts: { // https://github.com/Swatinem/rollup-plugin-dts/issues/143 compilerOptions: { preserveSymlinks: false }, respectExternal: true } } }; } async function getBuildContext(buildConfig, pkg) { var _a, _b, _c, _d, _e; const _options = beesBuildOption(); const rootDir = (pkg == null ? void 0 : pkg.path) || (buildConfig == null ? void 0 : buildConfig.rootDir) || _options.rootDir; if (!(pkg == null ? void 0 : pkg.buildConfig) || !(pkg == null ? void 0 : pkg.bin)) { const pkgPath = (_a = pkg == null ? void 0 : pkg.path) != null ? _a : rootDir; pkg = defu(getPackageManifest(path.resolve(pkgPath, ".", "package.json")), pkg != null ? pkg : {}); } const _buildConfig = tryRequire("./build.config", rootDir) || {}; const buildConfig_ = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).find(Boolean); const name = pkg.name.split("/").pop() || _options.name; const options = mergeWith( _options, buildConfig != null ? buildConfig : {}, (_b = pkg.unbuild || pkg.buildConfig || pkg.build) != null ? _b : {}, omit(buildConfig_, "entries"), { rootDir, name } ); if (!((_c = options == null ? void 0 : options.rollup) == null ? void 0 : _c.vue)) { const dependencies = [ ...Object.keys((_d = pkg.dependencies) != null ? _d : {}), ...Object.keys((_e = pkg.peerDependencies) != null ? _e : {}) ]; options.rollup.vue = dependencies.includes("vue"); } if (!options.rootDir) { options.rootDir = process.cwd(); } if (options.rollup.esbuild && options.rollup.esbuild.minify) { options.minify = false; } if (options.minify && options.rollup.esbuild) { options.rollup.esbuild.minify = false; } options.outDir = path.resolve(rootDir, (options == null ? void 0 : options.outDir) || "."); const ctx = { uid: Symbol(uniqueId(name)), options, argv: buildConfig, warnings: /* @__PURE__ */ new Set(), pkg, buildEntries: [], usedImports: /* @__PURE__ */ new Set(), hooks: createHooks(), caches: /* @__PURE__ */ new Set() }; return ctx; } export { getBuildContext };