node path.resolve()
作用:
path.resolve()方法将一系列路径或路径段解析为绝对路径。
语法:
path.resolve([from ...], to)
说明:将参数 to 位置的字符解析到一个绝对路径里。
参数说明
- from 源路径
- to 将被解析到绝对路径的字符串
用法:
1 var path = require('path');
2 var webpack = require('webpack');
3 var glob = require('glob')
4
5 //
6 var ROOT_PATH = path.resolve(__dirname);
7 var APP_PATH = path.resolve(ROOT_PATH, 'app');
8 var BUILD_PATH = path.resolve(ROOT_PATH, 'build');
实例:
1 path.resolve('/foo/bar', './baz')
2 // returns '/foo/bar/baz'
3
4 path.resolve('/foo/bar', '/tmp/file/')
5 // returns '/tmp/file'
6
7 path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
8 // if the current working directory is /home/myself/node,
9 // this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'
一点、一点才能到达彼岸