@gluonjs/compiler / packages/compiler/src / GluonSfcCompileResult
Interface: GluonSfcCompileResult
Properties
code
readonlycode:string
componentName
readonlycomponentName:string
layer
readonlylayer:GluonSfcLayer
styleId?
readonlyoptionalstyleId?:string
Example
Consume generated module code together with its component, layer, and optional owned stylesheet identity:
import {
GluonSfcCompileError,
compileGluonSfc,
type GluonSfcCompileOptions,
type GluonSfcCompileResult,
type GluonSfcLayer,
} from '@gluonjs/compiler';
const source = `
<script lang="ts">
export interface BadgeProps { readonly label: string; }
</script>
<template component="Badge" layer="atom" props="BadgeProps">
<strong>{{ label }}</strong>
</template>
<style id="docs-badge">.docs-badge { font-weight: 600; }</style>
`;
const options = { filename: '/src/Badge.gluon' } satisfies GluonSfcCompileOptions;
try {
const result: GluonSfcCompileResult = compileGluonSfc(source, options);
const layer: GluonSfcLayer = result.layer;
console.log(result.componentName, layer, result.styleId, result.code);
} catch (error) {
if (error instanceof GluonSfcCompileError) console.error(error.code, error.filename);
}