Skip to content

Instantly share code, notes, and snippets.

@DeMoorJasper
Last active May 3, 2018 09:50
Show Gist options
  • Save DeMoorJasper/6d1550268c4b3a1c6d29744d803965af to your computer and use it in GitHub Desktop.
Save DeMoorJasper/6d1550268c4b3a1c6d29744d803965af to your computer and use it in GitHub Desktop.
Parsing svelte
const { compile, preprocess } = require('svelte');
async parse(inputCode) {
let svelteOptions = {
compilerOptions: {
generate: 'dom',
format: 'cjs',
store: true,
filename: this.relativeName,
css: false
},
preprocess: undefined
};
const customConfig = await this.getConfig(['.svelterc', 'svelte.config.js', 'package.json']);
if (customConfig) {
svelteOptions = Object.assign(svelteOptions, customConfig.svelte || customConfig);
}
if (svelteOptions.preprocess) {
const preprocessed = await preprocess(inputCode, svelteOptions.preprocess);
inputCode = preprocessed.toString();
}
return compile(inputCode, svelteOptions.compilerOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment