UNPKG

vite-plugin-public-path

Version:

Vite's equivalent of `__webpack_public_path__` in Webpack. Works for `index.html` and modern/legacy build.

20 lines (19 loc) 834 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.processCode = void 0; const replacer_1 = require("../utils/replacer"); /** * Modern build of JS files import other chunks with relative path, but preload dependencies * and load CSS files with root-relative paths. * * Legacy build of JS files import other chunks with root-relative paths and embedding CSS files * in JS code. The root-relative URLs in embedded CSS files could be hard to replace. * * So we replace them with SWC's AST traversal. */ async function processCode(config, options, _fileName, code) { if (!code.includes(config.base)) return code; return await (0, replacer_1.replaceStringWithExpression)(code, config.base, options.publicPathExpression, !!config.build.minify); } exports.processCode = processCode;