一、dirname
作用:动态获取当前文件夹的绝对路径
二、filename
作用:动态获取当前文件的绝对路径
三、path.jion([path1][, path2][, ...])
作用:使用当前系统路径分隔符连接路径
四、path.resolve([from ...], to)
作用:相当于将from cd 到 to,/被解析为根路径。
console.log(__dirname); // F:myProjectvue.config.js console.log(__dirname); // F:myProject
let myPath = path.join(__dirname,'/img/so'); let myPath2 = path.join(__dirname,'./img/so'); let myPath3=path.join('/foo', 'bar', 'baz/asdf', 'quux', '..'); console.log(myPath); // F:myProjectimgso console.log(myPath2); // F:myProjectimgso console.log(myPath3); // F:myProjectfooararasdf **** ..表示返回上一层
let myPath = path.resolve(__dirname,'/img/so'); let myPath2 = path.resolve(__dirname,'./img/so'); let myPath3=path.resolve('/foo/bar', './baz'); let myPath4=path.resolve('/foo/bar', '/tmp/file/'); console.log(myPath); // imgso console.log(myPath2); // F:myProjectimgso console.log(myPath3); // fooarar console.log(myPath4); // mpfile