Skip to content

Commit

Permalink
Simplify setup
Browse files Browse the repository at this point in the history
  • Loading branch information
skovhus committed Jun 23, 2022
1 parent a1f4aef commit 6a4223e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 70 deletions.
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# vite-lingui

Example of how [Vite](https://vitejs.dev/) and [LinguiJS](https://lingui.js.org/) can co-exist using [vite-plugin-babel-macros](https://github.com/itsMapleLeaf/vite-plugin-babel-macros).
Example of how [Vite](https://vitejs.dev/) and [LinguiJS](https://lingui.js.org/) can co-exist.

The performance impact of this approach needs to be investigated, but it seems pretty fast. 🔎
There is a performance impact of using babel macros, but currently I haven't found any alternative. 🔎

One limitation is that the message catalogs is not compiled during the vite development process, which is normally considered best practice by using webpack loaders or a [snowpack plugin](https://lingui.js.org/ref/snowpack-plugin.html).
One limitation is that the message catalogs is not compiled during the vite development process, which is normally considered best practice by using webpack loaders or a [snowpack plugin](https://lingui.js.org/ref/snowpack-plugin.html).

This is an alternative to the solution suggested in https://github.com/capaj/vite-lingui-poc
This is an alternative to the rather complex solution suggested in https://github.com/capaj/vite-lingui-poc

To test it out:

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@vitejs/plugin-react": "^1.0.7",
"babel-plugin-macros": "^3.1.0",
"typescript": "^4.5.4",
"vite": "^2.8.0",
"vite-plugin-babel-macros": "^1.0.6"
"vite": "^2.8.0"
}
}
8 changes: 4 additions & 4 deletions src/locales/da/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ msgstr ""
"Language-Team: \n"
"Plural-Forms: \n"

#: src/App.tsx:49
#: src/App.tsx:55
msgid "Change language to {nextLanguage}"
msgstr "Skift sprog til {nextLanguage}"

#: src/App.tsx:37
#: src/App.tsx:43
msgid "Hello Vite + React + LinguiJS!"
msgstr "Hej Vite + React + LinguiJS!"

#: src/App.tsx:44
#: src/App.tsx:50
msgid "The count is: {count}"
msgstr "Tælleren er: {count}"

#: src/App.tsx:52
#: src/App.tsx:58
msgid "This is a translated message"
msgstr "Den er oversat"
8 changes: 4 additions & 4 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ msgstr ""
"Language-Team: \n"
"Plural-Forms: \n"

#: src/App.tsx:49
#: src/App.tsx:55
msgid "Change language to {nextLanguage}"
msgstr "Change language to {nextLanguage}"

#: src/App.tsx:37
#: src/App.tsx:43
msgid "Hello Vite + React + LinguiJS!"
msgstr "Hello Vite + React + LinguiJS!"

#: src/App.tsx:44
#: src/App.tsx:50
msgid "The count is: {count}"
msgstr "The count is: {count}"

#: src/App.tsx:52
#: src/App.tsx:58
msgid "This is a translated message"
msgstr "This is a translated message"
16 changes: 11 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import macrosPlugin from "vite-plugin-babel-macros";
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [macrosPlugin(), react()],
});
plugins: [
react({
babel: {
// babel-macro is needed for lingui
plugins: ['macros'],
},
}),
],
})
50 changes: 3 additions & 47 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.17.7.tgz#078d8b833fbbcc95286613be8c716cef2b519fa2"
integrity sha512-p8pdE6j0a29TNGebNm7NzYZWB3xVZJBZ7XGs42uAKzQo8VQ3F0By/cQCtUEABwIqw5zo6WA4NbmxsfzADzMKnQ==

"@babel/core@^7.16.12", "@babel/core@^7.17.7", "@babel/core@^7.17.8":
"@babel/core@^7.16.12", "@babel/core@^7.17.8":
version "7.17.8"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.17.8.tgz#3dac27c190ebc3a4381110d46c80e77efe172e1a"
integrity sha512-OdQDV/7cRBtJHLSOBqqbYNkOcydOgnX59TZx4puf41fzcVtN3e/4yqY8lMQsK+5X2lJtAdmA+6OHqsj1hBJ4IQ==
Expand Down Expand Up @@ -204,7 +204,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.11.5", "@babel/parser@^7.16.7", "@babel/parser@^7.17.3", "@babel/parser@^7.17.8":
"@babel/parser@^7.11.5", "@babel/parser@^7.16.7", "@babel/parser@^7.17.3", "@babel/parser@^7.17.8":
version "7.17.8"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.17.8.tgz#2817fb9d885dd8132ea0f8eb615a6388cca1c240"
integrity sha512-BoHhDJrJXqcg+ZL16Xv39H9n+AqJ4pcDrQBGZN+wHxIysrLZ3/ECwCBUch/1zUNhnsXULcONU3Ei5Hmkfk6kiQ==
Expand Down Expand Up @@ -332,7 +332,7 @@
debug "^4.1.0"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.11.5", "@babel/types@^7.16.7", "@babel/types@^7.17.0", "@babel/types@^7.3.0":
"@babel/types@^7.11.5", "@babel/types@^7.16.7", "@babel/types@^7.17.0":
version "7.17.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.17.0.tgz#a826e368bccb6b3d84acd76acad5c0d87342390b"
integrity sha512-TmKSNO4D5rzhL5bjWFcVHHLETzfQ/AmbKpKPOSjlP0WoHZ6L911fgoOKY4Alp/emzG4cHJdyN49zpgkbXFEHHw==
Expand Down Expand Up @@ -472,39 +472,6 @@
estree-walker "^2.0.1"
picomatch "^2.2.2"

"@types/babel__core@^7.1.18":
version "7.1.19"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.19.tgz#7b497495b7d1b4812bdb9d02804d0576f43ee460"
integrity sha512-WEOTgRsbYkvA/KCsDwVEGkd7WAr1e3g31VHQ8zy5gul/V1qKullU/BU5I68X5v7V3GnB9eotmom4v5a5gjxorw==
dependencies:
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"
"@types/babel__generator" "*"
"@types/babel__template" "*"
"@types/babel__traverse" "*"

"@types/babel__generator@*":
version "7.6.4"
resolved "https://registry.yarnpkg.com/@types/babel__generator/-/babel__generator-7.6.4.tgz#1f20ce4c5b1990b37900b63f050182d28c2439b7"
integrity sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==
dependencies:
"@babel/types" "^7.0.0"

"@types/babel__template@*":
version "7.4.1"
resolved "https://registry.yarnpkg.com/@types/babel__template/-/babel__template-7.4.1.tgz#3d1a48fd9d6c0edfd56f2ff578daed48f36c8969"
integrity sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==
dependencies:
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"

"@types/babel__traverse@*":
version "7.14.2"
resolved "https://registry.yarnpkg.com/@types/babel__traverse/-/babel__traverse-7.14.2.tgz#ffcd470bbb3f8bf30481678fb5502278ca833a43"
integrity sha512-K2waXdXBi2302XUdcHcR1jCeU0LL4TD9HRs/gk0N2Xvrht+G/BfJa4QObBQZfhMdxiCpV3COl5Nfq4uKTeTnJA==
dependencies:
"@babel/types" "^7.3.0"

"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz#8467d4b3c087805d63580480890791277ce35c44"
Expand Down Expand Up @@ -1850,17 +1817,6 @@ util-deprecate@^1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

vite-plugin-babel-macros@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/vite-plugin-babel-macros/-/vite-plugin-babel-macros-1.0.6.tgz#d05cee3c38c620ccb534e38f412fdd899a3365b5"
integrity sha512-7cCT8jtu5UjpE46pH7RyVltWw5FbhDAtQliZ6QGqRNR5RUZKdAsB0CDjuF+VBoDpnl0KuESPu22SoNqXRYYWyQ==
dependencies:
"@babel/core" "^7.17.7"
"@babel/plugin-syntax-jsx" "^7.16.7"
"@babel/plugin-syntax-typescript" "^7.16.7"
"@types/babel__core" "^7.1.18"
babel-plugin-macros "^3.1.0"

vite@^2.8.0:
version "2.8.6"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.8.6.tgz#32d50e23c99ca31b26b8ccdc78b1d72d4d7323d3"
Expand Down

0 comments on commit 6a4223e

Please sign in to comment.