1. Summary
Before running the full, expensive AST parsing pipeline on a file, perform a quick regular expression check to see if the file likely contains an html template.
2. Rationale
The current process parses every single .mjs file with acorn, which is computationally expensive. The vast majority of files in the project do not use html templates. By adding a quick pre-check, we can skip the entire AST transformation process for most files, significantly speeding up the overall build time.
3. Scope & Implementation Plan
- Define Regex: Create a simple, fast regex (e.g.,
/html\s*/`) to detect the presence of a tagged template literal.
- Implement Check: In
buildESModules.mjs, inside the minifyFile function, add a conditional check:
if (regex.test(content)) { ... }
- Conditional Processing: Only if the regex test passes, call the
processFileContent() function from the new astTemplateProcessor. If it fails, the content can be passed directly to the next step (Terser minification).
4. Definition of Done
- The regex check is implemented in
buildESModules.mjs.
- Files that do not contain
html templates are no longer processed by the astTemplateProcessor.
- Files that do contain
html templates are still transformed correctly.
- The overall build time is measurably reduced.
1. Summary
Before running the full, expensive AST parsing pipeline on a file, perform a quick regular expression check to see if the file likely contains an
htmltemplate.2. Rationale
The current process parses every single
.mjsfile withacorn, which is computationally expensive. The vast majority of files in the project do not usehtmltemplates. By adding a quick pre-check, we can skip the entire AST transformation process for most files, significantly speeding up the overall build time.3. Scope & Implementation Plan
/html\s*/`) to detect the presence of a tagged template literal.buildESModules.mjs, inside theminifyFilefunction, add a conditional check:if (regex.test(content)) { ... }processFileContent()function from the newastTemplateProcessor. If it fails, the content can be passed directly to the next step (Terser minification).4. Definition of Done
buildESModules.mjs.htmltemplates are no longer processed by theastTemplateProcessor.htmltemplates are still transformed correctly.