@revolist/svelte-output-target
Version:
Svelte output target for @stencil/core components.
30 lines (29 loc) • 1.53 kB
JavaScript
import path from 'path';
import { normalizePath } from './utils';
import { svelteProxyOutput } from './output-svelte';
export const normalizeOutputTarget = (config, outputTarget) => {
var _a, _b;
const results = Object.assign(Object.assign({}, outputTarget), { excludeComponents: outputTarget.excludeComponents || [], componentModels: outputTarget.componentModels || [], includePolyfills: (_a = outputTarget.includePolyfills) !== null && _a !== void 0 ? _a : true, includeDefineCustomElements: (_b = outputTarget.includeDefineCustomElements) !== null && _b !== void 0 ? _b : true });
if (config.rootDir == null) {
throw new Error('rootDir is not set and it should be set by stencil itself');
}
if (outputTarget.proxiesFile == null) {
throw new Error('proxiesFile is required');
}
if (outputTarget.directivesProxyFile && !path.isAbsolute(outputTarget.directivesProxyFile)) {
results.proxiesFile = normalizePath(path.join(config.rootDir, outputTarget.proxiesFile));
}
return results;
};
export const svelteOutputTarget = (outputTarget) => ({
type: 'custom',
name: 'svelte-library',
validate(config) {
return normalizeOutputTarget(config, outputTarget);
},
async generator(config, compilerCtx, buildCtx) {
const timespan = buildCtx.createTimeSpan('generate svelte started', true);
await svelteProxyOutput(config, compilerCtx, outputTarget, buildCtx.components);
timespan.finish('generate svelte finished');
},
});