How to use jiti.js.
This file contains 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
export default { | |
build:{ | |
output:"./" | |
} | |
} |
This file contains 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
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')) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can use jiti.js to help us read various file configurations at run time.