Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(atomic): add SVG transformer #4867

Merged
merged 7 commits into from
Jan 21, 2025
Merged

chore(atomic): add SVG transformer #4867

merged 7 commits into from
Jan 21, 2025

Conversation

y-lakhdar
Copy link
Contributor

@y-lakhdar y-lakhdar commented Jan 16, 2025

Update the Lit build process to be support SVG imports

Explanation

We are essentially creating a compiler which takes a list of TypeScript files (Lit components and dependencies) and compiles them to their corresponding JavaScript keeping the same file structure as in /src.
Typescript doc

To that compiler, I have added a SVG custom transformer.

Example

The following typescript file

import Tick from '../../../images/checkbox.svg';
() => console.log(Tick);

was transpiled to

import Tick from '../../../images/checkbox.svg';
() => console.log(Tick);

With the SVG transformer, we have

const Tick = "<svg viewBox=\"0 0 12 9\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n    <path d=\"M1.5 5L4.6 7.99999L11 1\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" />\n</svg>";
() => console.log(Tick);

Pseudo-code

  1. Load the TypeScript configuration file (tsconfig.lit.json)
  2. Create a default CompilerHost which uses the file system to get files (using program.emit function).
  3. To that program, provide a customTransformers which will essentially visit recursively tree nodes and check for svg import statements.
  4. When a SVG import statement is encountered, replace it with a "create variable statement" using the createVariableStatement typescript built-in method. Ensure to right-hand side of the assignation is the content of the .svg file

https://coveord.atlassian.net/browse/KIT-3865

Copy link

github-actions bot commented Jan 16, 2025

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 243.9 243.9 0
commerce 355.1 355.1 0
search 415 415 0
insight 406.3 406.3 0
recommendation 256.2 256.2 0
ssr 408.9 408.9 0
ssr-commerce 372.9 372.9 0

SSR Progress

Use case SSR (#) CSR (#) Progress (%)
search 39 44 89
recommendation 0 4 0
case-assist 0 6 0
insight 0 27 0
commerce 0 15 0
Detailed logs search : buildInteractiveResult
search : buildInteractiveInstantResult
search : buildInteractiveRecentResult
search : buildInteractiveCitation
search : buildGeneratedAnswer
recommendation : missing SSR support
case-assist : missing SSR support
insight : missing SSR support
commerce : missing SSR support

GitHub Actions Bot and others added 2 commits January 16, 2025 17:37
Copy link
Contributor

@alexprudhomme alexprudhomme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some jsdoc for every param and returns would be really useful here for future versions of typescript !

@y-lakhdar y-lakhdar added this pull request to the merge queue Jan 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 20, 2025
@y-lakhdar y-lakhdar added this pull request to the merge queue Jan 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 20, 2025
@y-lakhdar y-lakhdar added this pull request to the merge queue Jan 21, 2025
Merged via the queue into master with commit a331579 Jan 21, 2025
95 checks passed
@y-lakhdar y-lakhdar deleted the KIT-3865 branch January 21, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants