diff --git a/packages/taroize/package.json b/packages/taroize/package.json index 4b5afe145d22..fc1dcd3d6b8f 100644 --- a/packages/taroize/package.json +++ b/packages/taroize/package.json @@ -27,6 +27,7 @@ "babel-types": "^6.26.0", "babylon": "^6.18.0", "himalaya-wxml": "^1.1.0", + "html": "^1.0.0", "lodash": "^4.17.5", "typescript": "^3.0.1" }, diff --git a/packages/taroize/src/wxml.ts b/packages/taroize/src/wxml.ts index cc938721c275..db0f49227bb3 100644 --- a/packages/taroize/src/wxml.ts +++ b/packages/taroize/src/wxml.ts @@ -8,6 +8,7 @@ import { parseTemplate, parseModule } from './template' import { usedComponents, errors, globals } from './global' import { reserveKeyWords } from './constant' import { parse as parseFile } from 'babylon' +const { prettyPrint } = require('html') const allCamelCase = (str: string) => str.charAt(0).toUpperCase() + camelCase(str.substr(1)) @@ -298,6 +299,14 @@ export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean imports: Imports[] refIds: Set } { + try { + wxml = prettyPrint(wxml, { + max_char: 0, + unformatted: ['text'] + }) + } catch (error) { + // + } if (!parseImport) { errors.length = 0 usedComponents.clear()