webpack之node path.resolve()的解析

作用:
path.resolve()方法将一系列路径或路径段解析为绝对路径。

语法:

path.resolve([from ...], to)

说明:将参数 to 位置的字符解析到一个绝对路径里。

参数说明

from 源路径
to 将被解析到绝对路径的字符串
用法:

var path = require('path');
var webpack = require('webpack');
var glob = require('glob')

var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

实例:

path.resolve('/foo/bar', './baz')
// returns '/foo/bar/baz'

path.resolve('/foo/bar', '/tmp/file/')
// returns '/tmp/file'

path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
// if the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'

猜你喜欢

转载自blog.csdn.net/xiaolinlife/article/details/84963337