Skip to content

Instantly share code, notes, and snippets.

@dohooo
Created August 5, 2022 16:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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