"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.codegenCss = exports.cssPlugin = exports.debugCSS = void 0; const path_1 = require("path"); const hash_sum_1 = __importDefault(require("hash-sum")); const utils_1 = require("../utils"); const serverPluginVue_1 = require("./serverPluginVue"); const cssUtils_1 = require("../utils/cssUtils"); const querystring_1 = __importDefault(require("querystring")); const chalk_1 = __importDefault(require("chalk")); const serverPluginClient_1 = require("./serverPluginClient"); const pluginutils_1 = require("@rollup/pluginutils"); exports.debugCSS = require('debug')('vite:css'); exports.cssPlugin = ({ root, app, watcher, resolver }) => { app.use(async (ctx, next) => { await next(); // handle .css imports if (cssUtils_1.isCSSRequest(ctx.path) && // note ctx.body could be null if upstream set status to 304 ctx.body) { const id = JSON.stringify(hash_sum_1.default(ctx.path)); if (utils_1.isImportRequest(ctx)) { const { css, modules } = await processCss(root, ctx); ctx.type = 'js'; // we rewrite css with `?import` to a js module that inserts a style // tag linking to the actual raw url ctx.body = codegenCss(id, css, modules); } } }); watcher.on('change', (filePath) => { if (cssUtils_1.isCSSRequest(filePath)) { const publicPath = resolver.fileToRequest(filePath); /** filter unused files */ if (!cssUtils_1.cssImporterMap.has(filePath) && !processedCSS.has(publicPath) && !serverPluginVue_1.srcImportMap.has(filePath)) { return exports.debugCSS(`${path_1.basename(publicPath)} has changed, but it is not currently in use`); } if (serverPluginVue_1.srcImportMap.has(filePath)) { // handle HMR for