Skip to content

transform bundle so no runtime parsing is needed #68

@ivanhofer

Description

@ivanhofer

In its current implementation typesafe-i18n needs to parse each translation the first time it gets called. The parsing part is taking about half of the bundle size. The whole library could be trimmed to < 0.5 bytes if the parsing would take place compile-time.

Instead of this:

const en: Translation = {
   'HELLO': 'Hi {name:string}!'
}
export default en

the production bundle output could be:

const en: Translation = {
   'HELLO': ['Hi ', { k: 'name' }, '!']
}
export default en

This would mean slightly larger output for each translation file, but this should compress (gzip) better because of its repetitive pattern. If the parsing is not needed run-time, the library should be even faster (mostly nanoseconds).

What needs to be done:

  • evaluate the impact regarding bundle size
  • evaluate the time-savings if message parsing is not needed
  • implement an AST-transform function that parses and replaces each message
  • remove parsing part from output bundle

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is neededoptimizationThings that could reduce bundle-size or make it more efficient

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions