(DocPlugin): usePlayGround 自动格式化 CSS 语句

This commit is contained in:
sight 2022-06-24 01:04:33 +08:00
parent e3c2b471b3
commit d3d5f1e1a6

View File

@ -100,16 +100,14 @@ function trimBr(str: string): string {
* @returns
*/
async function formatCode(filename: string, data: string) {
const { format } = await import("prettier/standalone");
const parserTypeScript = await import("prettier/parser-typescript").then(
(m) => m.default
);
const parserBabel = await import("prettier/parser-babel").then(
(m) => m.default
);
const parserHtml = await import("prettier/parser-html").then(
(m) => m.default
);
const [format, parserHtml, parserTypeScript, parserBabel, parserPostcss] =
await Promise.all([
import("prettier/standalone").then((r) => r.format),
import("prettier/parser-html").then((m) => m.default),
import("prettier/parser-typescript").then((m) => m.default),
import("prettier/parser-babel").then((m) => m.default),
import("prettier/parser-postcss").then((m) => m.default),
]);
let code = data;
let parser: BuiltInParserName;
if (filename.endsWith(".vue")) {
@ -125,7 +123,7 @@ async function formatCode(filename: string, data: string) {
}
code = format(code, {
parser,
plugins: [parserHtml, parserTypeScript, parserBabel],
plugins: [parserHtml, parserTypeScript, parserBabel, parserPostcss],
semi: false, // 语句末尾打印分号
singleQuote: true, // 使用单引号
vueIndentScriptAndStyle: false, // 是否缩进 Vue 文件中的 script 和 style 标签