获取文件路径
可以用import对象中的meta属性获取,获取的路径并不利于使用
const currentUrl = import.meta.url
需要借用函数
import {fileURLToPath} from 'url'
const __filename = fileURLToPath(import.meta.url)
获取文件所在目录,需要先完成上一个步骤得到文件路径,然后借用函数
import {dirname} from 'path'
import {fileURLToPath} from 'url'
// 文件的路径
const __filename = fileURLToPath(import.meta.url)
// 先获取文件所在的目录
const __dirname = dirname(__filename)