@web/rollup-plugin-html
Version:
Rollup plugin for bundling HTML files
40 lines • 1.91 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractAssets = void 0;
const parse5_1 = require("parse5");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const utils_js_1 = require("../../assets/utils.js");
function extractAssets(params) {
const assetNodes = (0, utils_js_1.findAssets)(params.document);
const allAssets = [];
const isExternal = (0, utils_js_1.createAssetPicomatchMatcher)(params.externalAssets);
for (const node of assetNodes) {
const sourcePaths = (0, utils_js_1.getSourcePaths)(node);
for (const sourcePath of sourcePaths) {
if (isExternal(sourcePath))
continue;
const filePath = (0, utils_js_1.resolveAssetFilePath)(sourcePath, params.htmlDir, params.rootDir, params.absolutePathPrefix);
const hashed = (0, utils_js_1.isHashedAsset)(node);
const alreadyHandled = allAssets.find(a => a.filePath === filePath && a.hashed === hashed);
if (!alreadyHandled) {
try {
fs_1.default.accessSync(filePath);
}
catch (error) {
const elStr = (0, parse5_1.serialize)(node);
const htmlPath = path_1.default.relative(process.cwd(), params.htmlFilePath);
throw new Error(`Could not find ${filePath} referenced from HTML file ${htmlPath} from element ${elStr}.`);
}
const content = fs_1.default.readFileSync(filePath);
allAssets.push({ filePath, hashed, content });
}
}
}
return allAssets;
}
exports.extractAssets = extractAssets;
//# sourceMappingURL=extractAssets.js.map