@liip/esbuild-plugin-ast-vue
Version:
Esbuild plugin to parse Vue AST
46 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveStyle = resolveStyle;
const compiler_sfc_1 = require("@vue/compiler-sfc");
const convert_source_map_1 = require("convert-source-map");
const cache_1 = require("./cache");
async function resolveStyle({ filename, styleOptions = {}, index, isModule, moduleWithNameImport, isProd, }) {
const descriptor = (0, cache_1.getDescriptorCache)(filename);
const styleBlock = descriptor.styles[index];
const scopeId = (0, cache_1.getId)(filename);
const res = await (0, compiler_sfc_1.compileStyleAsync)({
source: styleBlock.content,
filename: descriptor.filename,
id: scopeId,
scoped: styleBlock.scoped,
trim: true,
isProd,
inMap: styleBlock.map,
preprocessLang: styleBlock.lang,
preprocessOptions: styleOptions.preprocessOptions,
postcssOptions: styleOptions.postcssOptions,
postcssPlugins: styleOptions.postcssPlugins,
modules: isModule,
modulesOptions: styleOptions.modulesOptions,
});
let styleCode;
if (moduleWithNameImport) {
// css-modules JSON file
styleCode = JSON.stringify(res.modules);
}
else {
// normal css content
styleCode = res.code;
}
if (res.map && !moduleWithNameImport) {
styleCode += (0, convert_source_map_1.fromObject)(res.map).toComment({ multiline: true });
}
const errors = res.errors.map((e) => ({
text: e.message,
}));
return {
errors,
styleCode,
};
}
//# sourceMappingURL=style.js.map