Skip to content

Instantly share code, notes, and snippets.

@ninetails
Last active July 16, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninetails/2f84baab9518006c5d45263f57726cc4 to your computer and use it in GitHub Desktop.
Save ninetails/2f84baab9518006c5d45263f57726cc4 to your computer and use it in GitHub Desktop.
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