Last active
July 16, 2019 21:36
-
-
Save ninetails/2f84baab9518006c5d45263f57726cc4 to your computer and use it in GitHub Desktop.
Jest transformer for Svelte 3 with preprocessor
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
const deasync = require('deasync') | |
const svelte = require('svelte/compiler') | |
const { stylus } = require('svelte-preprocess') | |
module.exports.process = (src, filename) => { | |
let result, error | |
svelte | |
.preprocess(src, [stylus()], { filename }) | |
.then(({ code }) => | |
svelte.compile(code, { | |
dev: true, | |
format: 'cjs', | |
filename | |
}) | |
) | |
.then(({ js: { code, map } }) => { | |
result = { code, map } | |
}) | |
.catch(err => { | |
error = err | |
console.error(err) | |
}) | |
deasync.loopWhile(() => !result && !error) // race condition | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment