UNPKG

piral-cli-vite

Version:

Provides debug and build capabilities for pilets and Piral instances using Vite.

96 lines 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.create = void 0; const vite_plugin_pilet_1 = __importDefault(require("vite-plugin-pilet")); const common_1 = require("./common"); const bundler_run_1 = require("./bundler-run"); function nameOf(path) { return path.replace(/\.js$/, ''); } function getPackageName() { return process.env.BUILD_PCKG_NAME; } function getRequireRef() { const name = getPackageName(); return `rolluppr_${name.replace(/\W/gi, '')}`; } const supportedSchemas = ['v2', 'v3']; function checkSupported(schema) { if (!supportedSchemas.includes(schema)) { throw new Error(`The provided schema version is not supported. This version supports: ${supportedSchemas.join(', ')}.`); } } const handler = { create(options) { const schema = options.version; const piletName = getPackageName(); const requireRef = getRequireRef(); const external = []; const id = nameOf(options.outFile); const input = { [id]: options.entryModule, }; // first populate with global externals options.externals.forEach((name) => { external.push(name); }); // then populate with distributed externals options.importmap.forEach((dep) => { external.push(dep.name); }); // finally add the local importmap entries to the bundler entry points options.importmap.forEach((dep) => { if (dep.type === 'local') { input[nameOf(dep.ref)] = dep.entry; } }); checkSupported(schema); const config = (0, common_1.createCommonConfig)(options.root, options.outDir, options.develop, options.sourceMaps, options.minify, {}); return (0, bundler_run_1.runVite)({ ...config, build: { ...config.build, lib: { entry: options.entryModule, fileName: () => options.outFile, formats: ['system'], }, rollupOptions: { ...config.build.rollupOptions, input, output: { ...config.build.rollupOptions.output, assetFileNames(assetInfo) { // keep name of combined stylesheet if (assetInfo.name === 'style.css') { return assetInfo.name; } return '[name].[hash][extname]'; }, entryFileNames: '[name].js', }, external, }, }, plugins: [ ...config.plugins, (0, vite_plugin_pilet_1.default)({ id, schema, piletName, requireRef, importmap: options.importmap, debug: options.develop, }), ], debug: options.watch, outFile: options.outFile, requireRef, }); }, }; exports.create = handler.create; //# sourceMappingURL=pilet.js.map