UNPKG

@soleil-se/build-app

Version:

Script for building WebApps, RESTApps, Widgets and MCP Servers with Svelte in Sitevision.

81 lines (72 loc) 2.63 kB
import { rollup } from 'rollup'; import json from '@rollup/plugin-json'; import { globSync } from 'glob'; import onwarn from './utils/onwarn.js'; import { getReplaceServerPlugin } from './api/getReplacePlugin.js'; import { getAliasServerPlugin } from './api/getAliasPlugin.js'; import { getBabelServerPlugin } from './api/getBabelPlugin.js'; import getCommonjsPlugin from './api/getCommonjsPlugin.js'; import getNodeResolvePlugin from './api/getNodeResolvePlugin.js'; import getSveltePlugin from './api/getSveltePlugin.js'; import getPostcssPlugin from './api/getPostcssPlugin.js'; import getTerserPlugin from './api/getTerserPlugin.js'; import getStringPlugin from './api/getStringPlugin.js'; import getTypescriptPlugin from './api/getTypescriptPlugin.js'; import sitevision from './plugins/sitevision.js'; import replaceReplaceAll from './plugins/replaceReplaceAll.js'; export default function rollupServer({ debug, input, output, extractCss = false, cache = true, } = {}) { let bundleCache; let plugins; return async () => { const inputs = globSync(input); if (inputs.length === 0) return Promise.resolve(); if (inputs.length > 1) throw new Error(`Multiple files found for input: ${inputs.join(', ').replace(/\\/g, '/')}`); plugins = plugins || [ getReplaceServerPlugin({ debug }), getAliasServerPlugin(), sitevision({ context: 'server' }), getTypescriptPlugin({ input: inputs[0] }), json(), getStringPlugin(), getNodeResolvePlugin({ input: inputs[0], debug }), getCommonjsPlugin(), getSveltePlugin({ input: inputs[0], extractCss, ssr: true }), getPostcssPlugin({ extractCss, debug }), getBabelServerPlugin(), replaceReplaceAll(), getTerserPlugin({ debug }), ]; try { const bundle = await rollup({ input: inputs[0], plugins, onwarn, cache: bundleCache, }); bundleCache = cache && bundle.cache; return bundle.write({ file: output, intro: /* js */` var Promise = Promise || { resolve: () => {} }; var global = global || this; var self = self || global; var globalThis = globalThis || global; var setTimeout = setTimeout || function(cb) { cb() }; function dynamicImportError(moduleName) { throw new Error('The module "' + moduleName + '" tried to be dynamically imported with "import", this is not supported in Rhino.'); } `, format: 'iife', }); } catch (e) { bundleCache = undefined; throw e; } }; }