UNPKG

@zougt/vite-plugin-theme-preprocessor

Version:
55 lines (54 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addExtractThemeLinkTag = addExtractThemeLinkTag; exports.default = void 0; var _someLoaderUtils = require("@zougt/some-loader-utils"); function addExtractThemeLinkTag({ html, defaultOptions, allmultipleScopeVars, buildCommand, config }) { // 向html中添加抽取的主题css文件的link标签,并在html标签中添加 calssName let newHtml = html; const tags = []; const { themeLinkTagInjectTo, extract, removeCssScopeName, themeLinkTagId, outputDir, defaultScopeName, customThemeCssFileName } = defaultOptions; if (Array.isArray(allmultipleScopeVars) && allmultipleScopeVars.length) { const scopeName = defaultScopeName || allmultipleScopeVars[0].scopeName; if (buildCommand !== "build" || !removeCssScopeName) { newHtml = (0, _someLoaderUtils.addScopnameToHtmlClassname)(newHtml, scopeName); } if (buildCommand === "build" && extract && themeLinkTagId) { const filename = (typeof customThemeCssFileName === "function" ? customThemeCssFileName(scopeName) : "") || scopeName; const base = config.base || ""; const linkHref = `${base ? `${base}/` : base}${outputDir || config.build.assetsDir}/${filename}.css`.replace(/(?<!:)\/+(?=\/)/g, ""); const tag = { tag: "link", attrs: { rel: "stylesheet", href: linkHref, id: themeLinkTagId }, injectTo: themeLinkTagInjectTo }; tags.push(tag); } } return { html: newHtml, tags }; } var _default = addExtractThemeLinkTag; exports.default = _default;