UNPKG

@equinor/fusion-framework-cli

Version:

--- title: Fusion Framework CLI ---

88 lines 3.88 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import nodePath from 'node:path'; import { defineConfig, mergeConfig } from 'vite'; import { createViteLogger } from './vite-logger.js'; import { AssertionError, assertObject } from './utils/assert.js'; import { loadConfig, resolveConfig, initiateConfig, } from './utils/config.js'; // Plugins import viteEnv from 'vite-plugin-environment'; import tsconfigPaths from 'vite-tsconfig-paths'; import { fileExistsSync } from './utils/file-exists.js'; const configFilename = 'app.vite.config'; export function assertViteConfig(config) { assertObject(config); } export const loadViteConfig = (filename) => loadConfig(filename !== null && filename !== void 0 ? filename : configFilename); export const resolveViteConfig = (options) => __awaiter(void 0, void 0, void 0, function* () { if (options === null || options === void 0 ? void 0 : options.file) { const config = yield loadViteConfig(options.file); return { config, path: options.file, }; } return resolveConfig(configFilename, { find: options }); }); export const createAppViteConfig = (env, options) => __awaiter(void 0, void 0, void 0, function* () { var _a; const resolved = yield resolveViteConfig(options); if (resolved) { const config = (_a = (yield initiateConfig(resolved.config, env))) !== null && _a !== void 0 ? _a : {}; return { config, path: resolved.path }; } else if (options === null || options === void 0 ? void 0 : options.file) { throw new AssertionError({ message: `Expected to load config from ${options.file}`, expected: '<file>', }); } }); export const resolveEntryPoint = (cwd, dir, opt) => { var _a; cwd !== null && cwd !== void 0 ? cwd : (cwd = process.cwd()); dir !== null && dir !== void 0 ? dir : (dir = 'src'); const files = (_a = opt === null || opt === void 0 ? void 0 : opt.files) !== null && _a !== void 0 ? _a : ['index.ts', 'index.tsx', 'main.ts', 'main.tsx']; return files .map((file) => [dir, file].join('/')) .find((file) => fileExistsSync(nodePath.resolve(cwd, file))); }; export const createViteConfig = (env, overrides) => __awaiter(void 0, void 0, void 0, function* () { var _a; const { root = process.cwd() } = env; const entry = String(resolveEntryPoint(root)); const defaultConfig = defineConfig({ plugins: [ tsconfigPaths(), viteEnv({ NODE_ENV: env.mode, FUSION_LOG_LEVEL: ((_a = process.env.FUSION_LOG_LEVEL) !== null && _a !== void 0 ? _a : env.mode === 'development') ? '3' : '1', }), ], mode: env.mode, root, appType: 'custom', build: { lib: { entry, fileName: 'app-bundle', formats: ['es'], }, rollupOptions: { output: { manualChunks: undefined, }, }, }, customLogger: createViteLogger(), }); return overrides ? mergeConfig(defaultConfig, overrides) : defaultConfig; }); //# sourceMappingURL=vite-config.js.map