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

Parse FTL files in plugin #101

Open
3 tasks done
rangermeier opened this issue Nov 13, 2024 · 2 comments · May be fixed by #107
Open
3 tasks done

Parse FTL files in plugin #101

rangermeier opened this issue Nov 13, 2024 · 2 comments · May be fixed by #107
Assignees
Labels
enhancement New feature or request

Comments

@rangermeier
Copy link

rangermeier commented Nov 13, 2024

Clear and concise description of the problem

I'm currently using ExternalFluentPlugin in a Vite project. When inspecting the output of the build process, i noticed that the FTL files are included in their raw state in the JS files. This means they have to be parsed into actual FluentResources when they are loaded by a user. I'm wondering what the overhead of this process is and - if it is not negligible - whether it would be possible to handle the parsing of FTL files by the plugin.

Suggested solution

The resulting FluentResource itself has only one property, body, which consists only of simple objects and strings.
So instead of instructing the browser to parse the raw file

import { FluentResource } from '@fluent/bundle'
export default new FluentResource(`
my-string = My String
`)

...it should be possible to serve the resulting resource:

export default {
  body: [{id: "my-string", value: "My String", attributes: {}}]
}

Additional context

As mentioned before, I'm not sure what actual effect this change would have on performance. Also, i don't know if this coudl also work for the SFCFluentPlugin.

Thanks anyway for this useful project!

Validations

@rangermeier rangermeier added the enhancement New feature or request label Nov 13, 2024
@Demivan Demivan self-assigned this Nov 13, 2024
@Demivan
Copy link
Member

Demivan commented Nov 13, 2024

Thanks for your interest in the library and opening a feature request.

When I was just starting the library, I have tested fluent.js runtime parser, and it was extremely fast. Parsing overhead was negligible compared to the actual formatting.
So I have decided to keep the raw ftl content and the resulting bundle size smaller.

But this is an idea that crossed my mind. I will make a benchmark comparing runtime parsing performance and the resulting bundle size with and without build-time parsing.

With the latest rewrite of unplugin-fluent-vue it should actually be trivial to add a flag to toggle between these two modes.

@Demivan Demivan linked a pull request Nov 16, 2024 that will close this issue
@Demivan
Copy link
Member

Demivan commented Nov 16, 2024

@rangermeier, I have added a PR that adds an option to enable build-time parsing: #107

You can use this command to try it out:

pnpm add https://pkg.pr.new/fluent-vue/unplugin-fluent-vue@107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

2 participants