vite-plugin-public-path
Version:
Vite's equivalent of `__webpack_public_path__` in Webpack. Works for `index.html` and modern/legacy build.
21 lines (20 loc) • 908 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processAsset = void 0;
/**
* For CSS and other some possible assets, which may reference other assets with URLs
* replace the root-relative URLs with relative URLs.
*/
function processAsset(config, _options, filename, content) {
const assetsPrefix = config.base + config.build.assetsDir + "/";
if (!content.includes(assetsPrefix)) {
/* istanbul ignore next */
if (content.includes(config.base)) {
throw new Error(`Unexpected error. Detected base placeholder but not base placeholder + assets dir. Couldn't determine relative URL. In file: ${filename}\n` +
"Please open an issue at https://github.com/Menci/vite-plugin-public-path/issues");
}
return content;
}
return content.split(assetsPrefix).join("");
}
exports.processAsset = processAsset;