opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
42 stars 0 forks source link

SvelteKit - Compiled translations in wrong dir #58

Closed UlrichRaab closed 6 months ago

UlrichRaab commented 6 months ago

I have defined a custom outdir in vite.config.ts but the compiled translations are not in the defined dir when i run npm run build. When i use npm run dev everything works as expected.

Here is my vite.config.ts:

import { paraglide } from '@inlang/paraglide-js-adapter-sveltekit/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
 plugins: [
  paraglide({
   project: './project.inlang',
   outdir: './src/gen/paraglide'
  }),
  sveltekit()
 ]
});
LorisSigrist commented 6 months ago

It's possible that you have a paraglide-js build CLI call in your package.json build script. Try removing it and re-running. Does the issue persist?

UlrichRaab commented 6 months ago

I used this guide and your example app to setup Paraglide. I have never added a build call to my package.json but there is paraglide-js compile --project ./project.inlang in scripts.build and postinstall.

Is this automatically generated when installing ParaglideJS or the SvelteKit Adapter?

{
    "name": "xxx",
    "version": "0.0.2",
    "private": true,
    "scripts": {
        "dev": "vite dev",
        "build": "paraglide-js compile --project ./project.inlang && vite build",
        "preview": "vite preview",
        "test": "npm run test:integration && npm run test:unit",
        "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
        "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
        "lint": "prettier --check . && eslint .",
        "format": "prettier --write .",
        "test:integration": "playwright test",
        "test:unit": "vitest",
        "postinstall": "paraglide-js compile --project ./project.inlang"
    },
    ...
}

I removed the call from scripts.build and it works as expected. Do i also have to remove postinstall?

Thank you for your support.

LorisSigrist commented 6 months ago

The call is automatically added by paraglide-js init. It does this because it can't be assumed that people are using a build tool like vite, so it adds calls to the compiler CLI.

You can safely remove the call from the build script. The postinstall script may be important if you are linting/typechecking in CI without building first, since the paraglide files would be missing. Add --outdir ./src/gen/paraglide to the command.

The newest version of the init CLI will always add the outdir flag to the commands to hopefully make it a little more transparent.

We should document this better