cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

How to use with Rollup? #8

Closed hmaesta closed 3 years ago

hmaesta commented 3 years ago

Hello Miguel, Thank you for your effort to improve i18n on Svelte.

I am currently using svelte-i18n and a good part of our bundle is the icu-messageformat-parser. I tried to install svelte-intl-precompile, but failed.

My rollup.config.js:

import precompileIntl from "svelte-intl-precompile/sveltekit-plugin";

export default {
  input: 'src/main.js',
  output: {
    sourcemap: true,
    format: 'iife',
    name: 'app',
    file: 'public/main.js',
  },
  plugins: [
    commonjs(),
    recompileIntl('i18n'),
  ]

I am getting:

Node tried to require an ES module from a CommonJS file, which is not supported

Is it possible to use with Rollup?

cibernox commented 3 years ago

@hmaesta sure, you totally can. Just add .cjs at the end of your import path. I created this repo so you can take a look: https://github.com/cibernox/svelte-precompile-with-rollup-app

hmaesta commented 3 years ago

It worked and I just saved 100 kb. 🙌

Thanks for the patience, Miguel. Have a nice week.

cibernox commented 3 years ago

wow, 100k of savings is a lot. How many translations does your app have?

hmaesta commented 3 years ago

Not so much, to be honest. Around 100 lines – but a lot with singular/plural variations. The biggest problem was:

file: /node_modules/@formatjs/icu-messageformat-parser/lib/parser.js original size: 48.151 KB

cibernox commented 3 years ago

Cool, let me know if you find anything that doesn't work. I for instance I'm aware that ordinals (1st, 2nd, 3rd) might not work yet, but afaik everything else should be working.