@swc/plugin-formatjs 6.0.0 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @swc/plugin-formatjs
2
2
 
3
+ ## 6.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 08db5e1: docs(formatjs): add Usage to readme
8
+ - beabfa1: Add proper README
9
+
10
+ ## 6.0.2
11
+
12
+ ### Patch Changes
13
+
14
+ - 27cae40: Disallow typescript types to shrink size
15
+
16
+ ## 6.0.1
17
+
18
+ ### Patch Changes
19
+
20
+ - df280ad: Update swc_core to v34.0.0
21
+
3
22
  ## 6.0.0
4
23
 
5
24
  ### Major Changes
package/README.md CHANGED
@@ -2,8 +2,118 @@
2
2
 
3
3
  FormatJS SWC plugin, maintained by SWC team.
4
4
 
5
+ ## Usage
6
+
7
+ The default message descriptors for the app's default language will be processed from: `defineMessages()`, `defineMessage()`, `intl.formatMessage` and `<FormattedMessage>`; all of which are named exports of the React Intl package.
8
+
9
+ ### Next.js
10
+
11
+ ```tsx
12
+ import { NextConfig } from 'next';
13
+
14
+ const nextConfig: NextConfig = {
15
+ experimental: {
16
+ swcPlugins: [
17
+ [
18
+ require.resolve('@swc/plugin-formatjs'),
19
+ {
20
+ idInterpolationPattern: '[md5:contenthash:hex:10]',
21
+ additionalComponentNames: ['F'],
22
+ ast: true,
23
+ },
24
+ ],
25
+ ],
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Vite
31
+ ```tsx
32
+ import react from '@vitejs/plugin-react-swc'
33
+ import { defineConfig } from 'vite'
34
+
35
+ export default defineConfig((env) => ({
36
+ plugins: [
37
+ react({
38
+ tsDecorators: true,
39
+ plugins: [
40
+ [
41
+ '@swc/plugin-formatjs',
42
+ {
43
+ idInterpolationPattern: '[md5:contenthash:hex:10]',
44
+ additionalComponentNames: ['F'],
45
+ ast: true,
46
+ },
47
+ ],
48
+ ],
49
+ }),
50
+ ]
51
+ }))
52
+ ```
53
+
54
+ ## Options
55
+
56
+ ### **`idInterpolationPattern`**
57
+
58
+ A template string that allows you to override the ID both in the extracted javascript and messages. It's used only if the message ID is empty.
59
+
60
+ ### **`removeDefaultMessage`**
61
+
62
+ Remove `defaultMessage` field in generated js after extraction.
63
+
64
+ ### **`extractSourceLocation`**
65
+
66
+ Whether the metadata about the location of the message in the source file should be extracted. If `true`, then `file`, `start`, and `end` fields will exist for each extracted message descriptors. Defaults to `false`.
67
+
68
+ ### **`additionalComponentNames`**
69
+
70
+ Additional component names to extract messages from, e.g: `['FormattedFooBarMessage']`. **NOTE**: By default we check for the fact that `FormattedMessage` are imported from `moduleSourceName` to make sure variable alias works. This option does not do that so it's less safe.
71
+
72
+ ### **`additionalFunctionNames`**
73
+
74
+ Additional function names to extract messages from, e.g: `['']`. Use this if you prefer to alias `formatMessage` to something shorter like ``.
75
+
76
+ ### **`ast`**
77
+
78
+ Pre-parse `defaultMessage` into AST for faster runtime perf. This flag doesn't do anything when `removeDefaultMessage` is `true`.
79
+
80
+ ### **`preserveWhitespace`**
81
+
82
+ Whether to preserve whitespace and newlines.
83
+
84
+ ### **`pragma`**
85
+
86
+ A string that allows you to extract metadata from comments in your source files. When set, the plugin will look for comments containing the pragma string and parse key:value pairs that follow it.
87
+
88
+ For example, with `pragma: "@formatjs"`, a comment like:
89
+
90
+ ```js
91
+ // @formatjs project:web locale:en region:us
92
+ ```
93
+
94
+ Will extract the metadata: `{project: "web", locale: "en", region: "us"}` that gets included with the extracted messages. This is useful for adding contextual information to your message extractions.
95
+
5
96
  # @swc/plugin-formatjs
6
97
 
98
+ ## 6.0.3
99
+
100
+ ### Patch Changes
101
+
102
+ - 08db5e1: docs(formatjs): add Usage to readme
103
+ - beabfa1: Add proper README
104
+
105
+ ## 6.0.2
106
+
107
+ ### Patch Changes
108
+
109
+ - 27cae40: Disallow typescript types to shrink size
110
+
111
+ ## 6.0.1
112
+
113
+ ### Patch Changes
114
+
115
+ - df280ad: Update swc_core to v34.0.0
116
+
7
117
  ## 6.0.0
8
118
 
9
119
  ### Major Changes
package/README.tmpl.md CHANGED
@@ -2,4 +2,95 @@
2
2
 
3
3
  FormatJS SWC plugin, maintained by SWC team.
4
4
 
5
+ ## Usage
6
+
7
+ The default message descriptors for the app's default language will be processed from: `defineMessages()`, `defineMessage()`, `intl.formatMessage` and `<FormattedMessage>`; all of which are named exports of the React Intl package.
8
+
9
+ ### Next.js
10
+
11
+ ```tsx
12
+ import { NextConfig } from 'next';
13
+
14
+ const nextConfig: NextConfig = {
15
+ experimental: {
16
+ swcPlugins: [
17
+ [
18
+ require.resolve('@swc/plugin-formatjs'),
19
+ {
20
+ idInterpolationPattern: '[md5:contenthash:hex:10]',
21
+ additionalComponentNames: ['F'],
22
+ ast: true,
23
+ },
24
+ ],
25
+ ],
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Vite
31
+ ```tsx
32
+ import react from '@vitejs/plugin-react-swc'
33
+ import { defineConfig } from 'vite'
34
+
35
+ export default defineConfig((env) => ({
36
+ plugins: [
37
+ react({
38
+ tsDecorators: true,
39
+ plugins: [
40
+ [
41
+ '@swc/plugin-formatjs',
42
+ {
43
+ idInterpolationPattern: '[md5:contenthash:hex:10]',
44
+ additionalComponentNames: ['F'],
45
+ ast: true,
46
+ },
47
+ ],
48
+ ],
49
+ }),
50
+ ]
51
+ }))
52
+ ```
53
+
54
+ ## Options
55
+
56
+ ### **`idInterpolationPattern`**
57
+
58
+ A template string that allows you to override the ID both in the extracted javascript and messages. It's used only if the message ID is empty.
59
+
60
+ ### **`removeDefaultMessage`**
61
+
62
+ Remove `defaultMessage` field in generated js after extraction.
63
+
64
+ ### **`extractSourceLocation`**
65
+
66
+ Whether the metadata about the location of the message in the source file should be extracted. If `true`, then `file`, `start`, and `end` fields will exist for each extracted message descriptors. Defaults to `false`.
67
+
68
+ ### **`additionalComponentNames`**
69
+
70
+ Additional component names to extract messages from, e.g: `['FormattedFooBarMessage']`. **NOTE**: By default we check for the fact that `FormattedMessage` are imported from `moduleSourceName` to make sure variable alias works. This option does not do that so it's less safe.
71
+
72
+ ### **`additionalFunctionNames`**
73
+
74
+ Additional function names to extract messages from, e.g: `['$formatMessage']`. Use this if you prefer to alias `formatMessage` to something shorter like `$t`.
75
+
76
+ ### **`ast`**
77
+
78
+ Pre-parse `defaultMessage` into AST for faster runtime perf. This flag doesn't do anything when `removeDefaultMessage` is `true`.
79
+
80
+ ### **`preserveWhitespace`**
81
+
82
+ Whether to preserve whitespace and newlines.
83
+
84
+ ### **`pragma`**
85
+
86
+ A string that allows you to extract metadata from comments in your source files. When set, the plugin will look for comments containing the pragma string and parse key:value pairs that follow it.
87
+
88
+ For example, with `pragma: "@formatjs"`, a comment like:
89
+
90
+ ```js
91
+ // @formatjs project:web locale:en region:us
92
+ ```
93
+
94
+ Will extract the metadata: `{project: "web", locale: "en", region: "us"}` that gets included with the extracted messages. This is useful for adding contextual information to your message extractions.
95
+
5
96
  ${CHANGELOG}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swc/plugin-formatjs",
3
- "version": "6.0.0",
3
+ "version": "6.0.3",
4
4
  "description": "FormatJS SWC plugin",
5
5
  "main": "swc_plugin_formatjs.wasm",
6
6
  "homepage": "https://swc.rs",
Binary file