Skip to content

Commit

Permalink
chore(parse5): update parse5 bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Jul 28, 2020
1 parent 9d0a72b commit be4f16d
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions scripts/bundles/plugins/parse5-plugin.ts
Expand Up @@ -67,24 +67,19 @@ async function bundleParse5(opts: BuildOptions) {

const { output } = await rollupBuild.generate({
format: 'iife',
name: 'EXPORT_PARSE5',
footer: `
export function parse(html, options) {
return parse5.parse(html, options);
}
export function parseFragment(html, options) {
return parse5.parseFragment(html, options);
}
`,
name: 'PARSE5',
footer: ['export const parse = PARSE5.parse;', 'export const parseFragment = PARSE5.parseFragment;'].join('\n'),
preferConst: true,
strict: false,
});

let code = output[0].code;

const minify = terser.minify(code);
const minified = terser.minify(output[0].code);

code = minify.code.replace('var EXPORT_PARSE5=function', 'const parse5=/*@__PURE__*/function');
if (minified.error) {
throw minified.error;
}

await fs.writeFile(cacheFile, code);
await fs.writeFile(cacheFile, minified.code);

return code;
return minified.code;
}

0 comments on commit be4f16d

Please sign in to comment.