webpack/lib/util/identifier.js

17 lines
434 B
JavaScript
Raw Normal View History

"use strict";
const path = require("path");
2017-04-07 21:37:38 +08:00
const looksLikeAbsolutePath = (maybeAbsolutePath) => {
return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
};
2017-04-07 21:37:38 +08:00
const normalizePathSeparator = (p) => p.replace(/\\/g, "/");
exports.makePathsRelative = (context, identifier) => {
return identifier
.split(/([|! ])/)
2017-04-07 21:37:38 +08:00
.map(str => looksLikeAbsolutePath(str) ?
normalizePathSeparator(path.relative(context, str)) : str)
.join("");
};