Last active
August 12, 2019 15:37
-
-
Save luiz/3161b4a986f1f5a82ba5cd667070b7f9 to your computer and use it in GitHub Desktop.
Code that does not compile with Svelte 3.8.0 and Typescript 3.5.3
This file contains hidden or 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
import * as sass from 'node-sass'; | |
import * as svelte from 'svelte/compiler'; | |
import * as fs from 'fs'; | |
import { promisify } from 'util'; | |
const renderSass = promisify(sass.render); | |
const readFile = promisify(fs.readFile); | |
const preprocessSass = async (data: string) => { | |
const result = await renderSass({ data }); | |
return { | |
code: result.css.toString(), | |
}; | |
}; | |
export const load = async (fileName: string) => { | |
const source = await readFile(fileName).then(buffer => buffer.toString()); | |
const preprocessedSource = await svelte.preprocess(source, { | |
// compilation fails here | |
style: (input) => preprocessSass(input.content), | |
}); | |
return svelte.parse(preprocessedSource.code); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment