Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jest transformer for Svelte 3 with preprocessor
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