Last active
May 3, 2018 09:50
-
-
Save DeMoorJasper/6d1550268c4b3a1c6d29744d803965af to your computer and use it in GitHub Desktop.
Parsing svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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