Skip to content

Instantly share code, notes, and snippets.

@dohooo
Created August 5, 2022 16:23
Show Gist options
  • Save dohooo/ea98760f174d621962f423f9fddef598 to your computer and use it in GitHub Desktop.
Save dohooo/ea98760f174d621962f423f9fddef598 to your computer and use it in GitHub Desktop.
How to use jiti.js.
export default {
build:{
output:"./"
}
}
import jiti from 'jiti'
;(async () => {
const filePath = import.meta.url
const fn = await jiti(filePath, { esmResolve: true, debug: true })
// Relative file path. './config.js'
console.log(fn('./config.js').default)
})()
// or
;(async () => {
const filePath = import.meta.url
const fn = await jiti(filePath, { esmResolve: true, debug: true, interopDefault: true })
// Relative file path. './config.js'
console.log(fn('./config.js'))
})()
@dohooo
Copy link
Author

dohooo commented Aug 5, 2022

We can use jiti.js to help us read various file configurations at run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment