vite-intlayer 5.5.0 → 5.5.2
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/README.md +129 -22
- package/dist/cjs/index.cjs +3 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/intlayerPlugin.cjs +64 -51
- package/dist/cjs/intlayerPlugin.cjs.map +1 -1
- package/dist/cjs/intlayerPrunePlugin.cjs +76 -0
- package/dist/cjs/intlayerPrunePlugin.cjs.map +1 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/intlayerPlugin.mjs +64 -51
- package/dist/esm/intlayerPlugin.mjs.map +1 -1
- package/dist/esm/intlayerPrunePlugin.mjs +52 -0
- package/dist/esm/intlayerPrunePlugin.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/intlayerPlugin.d.ts +4 -2
- package/dist/types/intlayerPlugin.d.ts.map +1 -1
- package/dist/types/intlayerPrunePlugin.d.ts +3 -0
- package/dist/types/intlayerPrunePlugin.d.ts.map +1 -0
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -16,11 +16,16 @@
|
|
|
16
16
|
/>
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
# vite-intlayer
|
|
19
|
+
# vite-intlayer
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration.
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Automatic Dictionary Resolution**: Resolves dictionary paths and configurations
|
|
26
|
+
- **Hot Reload Support**: Watches for dictionary changes during development
|
|
27
|
+
- **Babel Transform Plugin**: Automatically transforms `useIntlayer` calls to `useDictionary` calls at build time
|
|
28
|
+
- **TypeScript Support**: Full TypeScript support with proper type definitions
|
|
24
29
|
|
|
25
30
|
## Why Internationalize Your Vite Application?
|
|
26
31
|
|
|
@@ -32,43 +37,145 @@ The `vite-intlayer` package works seamlessly with the [`react-intlayer` package]
|
|
|
32
37
|
|
|
33
38
|
## Installation
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
```bash packageManager="npm"
|
|
40
|
+
```bash
|
|
38
41
|
npm install vite-intlayer
|
|
42
|
+
# or
|
|
43
|
+
pnpm add vite-intlayer
|
|
44
|
+
# or
|
|
45
|
+
yarn add vite-intlayer
|
|
39
46
|
```
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
### Basic Setup
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
// vite.config.ts
|
|
54
|
+
import { defineConfig } from "vite";
|
|
55
|
+
import { intlayerPlugin } from "vite-intlayer";
|
|
56
|
+
|
|
57
|
+
export default defineConfig({
|
|
58
|
+
plugins: [intlayerPlugin()],
|
|
59
|
+
});
|
|
43
60
|
```
|
|
44
61
|
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
### Configuration Options
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// vite.config.ts
|
|
66
|
+
import { defineConfig } from "vite";
|
|
67
|
+
import { intlayerPlugin } from "vite-intlayer";
|
|
68
|
+
|
|
69
|
+
export default defineConfig({
|
|
70
|
+
plugins: [
|
|
71
|
+
intlayerPlugin({
|
|
72
|
+
enableBabelTransform: true, // Enable automatic useIntlayer transformation (default: true)
|
|
73
|
+
}),
|
|
74
|
+
],
|
|
75
|
+
});
|
|
47
76
|
```
|
|
48
77
|
|
|
49
|
-
##
|
|
78
|
+
## Babel Plugin: Automatic useIntlayer Transformation
|
|
50
79
|
|
|
51
|
-
|
|
80
|
+
The plugin includes a Babel transformation that automatically converts `useIntlayer` calls to `useDictionary` calls at build time, providing better performance and tree-shaking.
|
|
52
81
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
### Transformation Example
|
|
83
|
+
|
|
84
|
+
**Input:**
|
|
56
85
|
|
|
57
|
-
|
|
86
|
+
```tsx
|
|
87
|
+
import { useIntlayer } from "react-intlayer";
|
|
88
|
+
|
|
89
|
+
function MyComponent() {
|
|
90
|
+
const content = useIntlayer("home-content");
|
|
91
|
+
const otherContent = useIntlayer("about-page", "en");
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div>
|
|
95
|
+
<h1>{content.title}</h1>
|
|
96
|
+
<p>{otherContent.description}</p>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Output:**
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import homeContentDictionary from "./.intlayer/dictionary/home-content.json";
|
|
106
|
+
import aboutPageDictionary from "./.intlayer/dictionary/about-page.json";
|
|
107
|
+
import { useDictionary } from "react-intlayer";
|
|
108
|
+
|
|
109
|
+
function MyComponent() {
|
|
110
|
+
const content = useDictionary(homeContentDictionary);
|
|
111
|
+
const otherContent = useDictionary(aboutPageDictionary, "en");
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div>
|
|
115
|
+
<h1>{content.title}</h1>
|
|
116
|
+
<p>{otherContent.description}</p>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Benefits of the Transformation
|
|
123
|
+
|
|
124
|
+
1. **Better Performance**: Direct dictionary access instead of key-based lookup
|
|
125
|
+
2. **Tree Shaking**: Unused dictionaries can be eliminated from the bundle
|
|
126
|
+
3. **Type Safety**: Better TypeScript inference with direct dictionary references
|
|
127
|
+
4. **Build-time Optimization**: Transformation happens at build time, not runtime
|
|
128
|
+
5. **Individual File Loading**: Only the dictionaries you use are imported, reducing bundle size
|
|
129
|
+
6. **Better Caching**: Individual dictionary files can be cached separately by the browser
|
|
130
|
+
|
|
131
|
+
### Using the Babel Plugin Separately
|
|
132
|
+
|
|
133
|
+
You can also use the Babel plugin independently:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
// babel.config.js
|
|
137
|
+
import { babelPluginIntlayer } from "vite-intlayer";
|
|
138
|
+
|
|
139
|
+
export default {
|
|
140
|
+
plugins: [
|
|
141
|
+
babelPluginIntlayer,
|
|
142
|
+
// other plugins...
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Disabling the Transformation
|
|
148
|
+
|
|
149
|
+
If you prefer to use `useIntlayer` without transformation:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// vite.config.ts
|
|
58
153
|
export default defineConfig({
|
|
59
|
-
plugins: [
|
|
154
|
+
plugins: [
|
|
155
|
+
intlayerPlugin({
|
|
156
|
+
enableBabelTransform: false,
|
|
157
|
+
}),
|
|
158
|
+
],
|
|
60
159
|
});
|
|
61
160
|
```
|
|
62
161
|
|
|
63
|
-
|
|
162
|
+
## How It Works
|
|
163
|
+
|
|
164
|
+
1. **Dictionary Resolution**: The plugin resolves paths to generated dictionaries and configurations
|
|
165
|
+
2. **Alias Setup**: Sets up Vite aliases for dictionary entry points
|
|
166
|
+
3. **Watch Mode**: In development, watches for dictionary changes and triggers rebuilds
|
|
167
|
+
4. **Babel Transformation**: Transforms `useIntlayer` calls to `useDictionary` calls for better performance
|
|
64
168
|
|
|
65
|
-
|
|
169
|
+
## Related Packages
|
|
66
170
|
|
|
67
|
-
|
|
171
|
+
- [`@intlayer/dictionaries-entry`](../dictionaries-entry): Dictionary entry point package
|
|
172
|
+
- [`react-intlayer`](../react-intlayer): React integration for Intlayer
|
|
173
|
+
- [`@intlayer/config`](../config): Configuration management
|
|
174
|
+
- [`@intlayer/chokidar`](../chokidar): File watching and dictionary building
|
|
68
175
|
|
|
69
|
-
|
|
176
|
+
## License
|
|
70
177
|
|
|
71
|
-
|
|
178
|
+
Apache-2.0
|
|
72
179
|
|
|
73
180
|
## Read about Intlayer
|
|
74
181
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -15,11 +15,11 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
__reExport(index_exports, require('./intlayerPlugin.cjs'), module.exports);
|
|
19
18
|
__reExport(index_exports, require('./intlayerMiddlewarePlugin.cjs'), module.exports);
|
|
19
|
+
__reExport(index_exports, require('./intlayerPlugin.cjs'), module.exports);
|
|
20
20
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
21
|
0 && (module.exports = {
|
|
22
|
-
...require('./
|
|
23
|
-
...require('./
|
|
22
|
+
...require('./intlayerMiddlewarePlugin.cjs'),
|
|
23
|
+
...require('./intlayerPlugin.cjs')
|
|
24
24
|
});
|
|
25
25
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './intlayerMiddlewarePlugin';\nexport * from './intlayerPlugin';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,uCAAd;AACA,0BAAc,6BADd;","names":[]}
|
|
@@ -24,60 +24,73 @@ module.exports = __toCommonJS(intlayerPlugin_exports);
|
|
|
24
24
|
var import_chokidar = require("@intlayer/chokidar");
|
|
25
25
|
var import_config = require("@intlayer/config");
|
|
26
26
|
var import_path = require("path");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
27
|
+
var import_intlayerPrunePlugin = require('./intlayerPrunePlugin.cjs');
|
|
28
|
+
const intlayerPlugin = (pluginOptions = {}) => {
|
|
29
|
+
const { enableBabelTransform = process.env.NODE_ENV === "production" } = pluginOptions;
|
|
30
|
+
const plugins = [
|
|
31
|
+
{
|
|
32
|
+
name: "vite-intlayer-plugin",
|
|
33
|
+
config: (config) => {
|
|
34
|
+
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
35
|
+
const {
|
|
36
|
+
mainDir,
|
|
37
|
+
configDir,
|
|
38
|
+
baseDir,
|
|
39
|
+
watch: isWatchMode
|
|
40
|
+
} = intlayerConfig.content;
|
|
41
|
+
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
|
|
42
|
+
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
43
|
+
const unmergedDictionariesPath = (0, import_path.join)(
|
|
44
|
+
mainDir,
|
|
45
|
+
"unmerged_dictionaries.mjs"
|
|
46
|
+
);
|
|
47
|
+
const relativeUnmergedDictionariesPath = (0, import_path.relative)(
|
|
48
|
+
baseDir,
|
|
49
|
+
unmergedDictionariesPath
|
|
50
|
+
);
|
|
51
|
+
const configurationPath = (0, import_path.join)(configDir, "configuration.json");
|
|
52
|
+
const relativeConfigurationPath = (0, import_path.relative)(baseDir, configurationPath);
|
|
53
|
+
config.resolve = {
|
|
54
|
+
...config.resolve,
|
|
55
|
+
alias: {
|
|
56
|
+
...config.resolve?.alias,
|
|
57
|
+
"@intlayer/dictionaries-entry": (0, import_path.resolve)(relativeDictionariesPath),
|
|
58
|
+
"@intlayer/unmerged-dictionaries-entry": (0, import_path.resolve)(
|
|
59
|
+
relativeUnmergedDictionariesPath
|
|
60
|
+
),
|
|
61
|
+
"@intlayer/config/built": (0, import_path.resolve)(relativeConfigurationPath)
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (isWatchMode) {
|
|
65
|
+
config.optimizeDeps = {
|
|
66
|
+
...config.optimizeDeps,
|
|
67
|
+
exclude: [
|
|
68
|
+
...config.optimizeDeps?.exclude ?? [],
|
|
69
|
+
"@intlayer/dictionaries-entry",
|
|
70
|
+
"@intlayer/unmerged-dictionaries-entry",
|
|
71
|
+
"@intlayer/config/built"
|
|
72
|
+
]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return config;
|
|
76
|
+
},
|
|
77
|
+
configureServer: async () => {
|
|
78
|
+
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
79
|
+
if (intlayerConfig.content.watch) {
|
|
80
|
+
(0, import_chokidar.watch)({ configuration: intlayerConfig });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
buildStart: async () => {
|
|
84
|
+
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
85
|
+
await (0, import_chokidar.prepareIntlayer)(intlayerConfig);
|
|
55
86
|
}
|
|
56
|
-
};
|
|
57
|
-
if (isWatchMode) {
|
|
58
|
-
config.optimizeDeps = {
|
|
59
|
-
...config.optimizeDeps,
|
|
60
|
-
exclude: [
|
|
61
|
-
...config.optimizeDeps?.exclude ?? [],
|
|
62
|
-
"@intlayer/dictionaries-entry",
|
|
63
|
-
"@intlayer/unmerged-dictionaries-entry",
|
|
64
|
-
"@intlayer/config/built"
|
|
65
|
-
]
|
|
66
|
-
};
|
|
67
87
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
72
|
-
if (intlayerConfig.content.watch) {
|
|
73
|
-
(0, import_chokidar.watch)({ configuration: intlayerConfig });
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
buildStart: async () => {
|
|
77
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
78
|
-
await (0, import_chokidar.prepareIntlayer)(intlayerConfig);
|
|
88
|
+
];
|
|
89
|
+
if (enableBabelTransform) {
|
|
90
|
+
plugins.push((0, import_intlayerPrunePlugin.IntlayerPrunePlugin)());
|
|
79
91
|
}
|
|
80
|
-
|
|
92
|
+
return plugins;
|
|
93
|
+
};
|
|
81
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
95
|
0 && (module.exports = {
|
|
83
96
|
intlayerPlugin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport { join, relative, resolve } from 'path';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { type PluginOption } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerPlugin() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport { join, relative, resolve } from 'path';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { type PluginOption } from 'vite';\nimport { IntlayerPrunePlugin } from './intlayerPrunePlugin';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n enableBabelTransform?: boolean;\n};\n\n/**\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerPlugin() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n pluginOptions: PluginOptions = {}\n): PluginOption => {\n const { enableBabelTransform = process.env.NODE_ENV === 'production' } =\n pluginOptions;\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: (config) => {\n const intlayerConfig = getConfiguration();\n const {\n mainDir,\n configDir,\n baseDir,\n watch: isWatchMode,\n } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n const unmergedDictionariesPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n\n const configurationPath = join(configDir, 'configuration.json');\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n '@intlayer/unmerged-dictionaries-entry': resolve(\n relativeUnmergedDictionariesPath\n ),\n '@intlayer/config/built': resolve(relativeConfigurationPath),\n },\n };\n\n if (isWatchMode) {\n // Ajout de l'option optimizeDeps.exclude\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [\n ...(config.optimizeDeps?.exclude ?? []),\n '@intlayer/dictionaries-entry',\n '@intlayer/unmerged-dictionaries-entry',\n '@intlayer/config/built',\n ],\n };\n }\n\n return config;\n },\n\n configureServer: async () => {\n // Runs when the dev server starts\n const intlayerConfig = getConfiguration();\n\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n\n buildStart: async () => {\n // Code to run when Vite build starts\n const intlayerConfig = getConfiguration();\n await prepareIntlayer(intlayerConfig);\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n if (enableBabelTransform) {\n plugins.push(IntlayerPrunePlugin());\n }\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuC;AACvC,oBAAiC;AACjC,kBAAwC;AAGxC,iCAAoC;AAmB7B,MAAM,iBAAiB,CAC5B,gBAA+B,CAAC,MACf;AACjB,QAAM,EAAE,uBAAuB,QAAQ,IAAI,aAAa,aAAa,IACnE;AAEF,QAAM,UAA0B;AAAA,IAC9B;AAAA,MACE,MAAM;AAAA,MAEN,QAAQ,CAAC,WAAW;AAClB,cAAM,qBAAiB,gCAAiB;AACxC,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA,OAAO;AAAA,QACT,IAAI,eAAe;AAEnB,cAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,cAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAEnE,cAAM,+BAA2B;AAAA,UAC/B;AAAA,UACA;AAAA,QACF;AACA,cAAM,uCAAmC;AAAA,UACvC;AAAA,UACA;AAAA,QACF;AAEA,cAAM,wBAAoB,kBAAK,WAAW,oBAAoB;AAC9D,cAAM,gCAA4B,sBAAS,SAAS,iBAAiB;AAGrE,eAAO,UAAU;AAAA,UACf,GAAG,OAAO;AAAA,UACV,OAAO;AAAA,YACL,GAAG,OAAO,SAAS;AAAA,YACnB,oCAAgC,qBAAQ,wBAAwB;AAAA,YAChE,6CAAyC;AAAA,cACvC;AAAA,YACF;AAAA,YACA,8BAA0B,qBAAQ,yBAAyB;AAAA,UAC7D;AAAA,QACF;AAEA,YAAI,aAAa;AAEf,iBAAO,eAAe;AAAA,YACpB,GAAG,OAAO;AAAA,YACV,SAAS;AAAA,cACP,GAAI,OAAO,cAAc,WAAW,CAAC;AAAA,cACrC;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,eAAO;AAAA,MACT;AAAA,MAEA,iBAAiB,YAAY;AAE3B,cAAM,qBAAiB,gCAAiB;AAExC,YAAI,eAAe,QAAQ,OAAO;AAEhC,qCAAM,EAAE,eAAe,eAAe,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,MAEA,YAAY,YAAY;AAEtB,cAAM,qBAAiB,gCAAiB;AACxC,kBAAM,iCAAgB,cAAc;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAGA,MAAI,sBAAsB;AACxB,YAAQ,SAAK,gDAAoB,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var intlayerPrunePlugin_exports = {};
|
|
20
|
+
__export(intlayerPrunePlugin_exports, {
|
|
21
|
+
IntlayerPrunePlugin: () => IntlayerPrunePlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(intlayerPrunePlugin_exports);
|
|
24
|
+
var import_babel = require("@intlayer/babel");
|
|
25
|
+
var import_config = require("@intlayer/config");
|
|
26
|
+
const IntlayerPrunePlugin = () => ({
|
|
27
|
+
name: "vite-intlayer-babel-transform",
|
|
28
|
+
transform(code, id) {
|
|
29
|
+
const fileExtensionPattern = /\.(tsx?|jsx?|vue|svelte|cjs|mjs|js|cjx|mjx)$/;
|
|
30
|
+
if (!fileExtensionPattern.test(id)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!code.includes("useIntlayer")) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const babel = (0, import_config.ESMxCJSRequire)("@babel/core");
|
|
38
|
+
const result = babel.transformSync(code, {
|
|
39
|
+
filename: id,
|
|
40
|
+
plugins: [import_babel.babelPluginIntlayer],
|
|
41
|
+
parserOpts: {
|
|
42
|
+
sourceType: "module",
|
|
43
|
+
allowImportExportEverywhere: true,
|
|
44
|
+
plugins: [
|
|
45
|
+
"typescript",
|
|
46
|
+
"jsx",
|
|
47
|
+
"decorators-legacy",
|
|
48
|
+
"classProperties",
|
|
49
|
+
"objectRestSpread",
|
|
50
|
+
"asyncGenerators",
|
|
51
|
+
"functionBind",
|
|
52
|
+
"exportDefaultFrom",
|
|
53
|
+
"exportNamespaceFrom",
|
|
54
|
+
"dynamicImport",
|
|
55
|
+
"nullishCoalescingOperator",
|
|
56
|
+
"optionalChaining"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (result?.code) {
|
|
61
|
+
return {
|
|
62
|
+
code: result.code,
|
|
63
|
+
map: result.map
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn("Failed to transform with Babel plugin:", error);
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
IntlayerPrunePlugin
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=intlayerPrunePlugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { babelPluginIntlayer } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => ({\n name: 'vite-intlayer-babel-transform',\n transform(code, id) {\n // Only transform React/TypeScript files\n const fileExtensionPattern = /\\.(tsx?|jsx?|vue|svelte|cjs|mjs|js|cjx|mjx)$/;\n if (!fileExtensionPattern.test(id)) {\n return null;\n }\n\n // Only transform files that contain useIntlayer\n if (!code.includes('useIntlayer')) {\n return null;\n }\n\n try {\n const babel = ESMxCJSRequire('@babel/core');\n const result = babel.transformSync(code, {\n filename: id,\n plugins: [babelPluginIntlayer],\n parserOpts: {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n },\n });\n\n if (result?.code) {\n return {\n code: result.code,\n map: result.map,\n };\n }\n } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n }\n\n return null;\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAoC;AACpC,oBAA+B;AAGxB,MAAM,sBAAsB,OAAqB;AAAA,EACtD,MAAM;AAAA,EACN,UAAU,MAAM,IAAI;AAElB,UAAM,uBAAuB;AAC7B,QAAI,CAAC,qBAAqB,KAAK,EAAE,GAAG;AAClC,aAAO;AAAA,IACT;AAGA,QAAI,CAAC,KAAK,SAAS,aAAa,GAAG;AACjC,aAAO;AAAA,IACT;AAEA,QAAI;AACF,YAAM,YAAQ,8BAAe,aAAa;AAC1C,YAAM,SAAS,MAAM,cAAc,MAAM;AAAA,QACvC,UAAU;AAAA,QACV,SAAS,CAAC,gCAAmB;AAAA,QAC7B,YAAY;AAAA,UACV,YAAY;AAAA,UACZ,6BAA6B;AAAA,UAC7B,SAAS;AAAA,YACP;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAED,UAAI,QAAQ,MAAM;AAChB,eAAO;AAAA,UACL,MAAM,OAAO;AAAA,UACb,KAAK,OAAO;AAAA,QACd;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,KAAK,0CAA0C,KAAK;AAAA,IAC9D;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './intlayerMiddlewarePlugin';\nexport * from './intlayerPlugin';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,60 +1,73 @@
|
|
|
1
1
|
import { prepareIntlayer, watch } from "@intlayer/chokidar";
|
|
2
2
|
import { getConfiguration } from "@intlayer/config";
|
|
3
3
|
import { join, relative, resolve } from "path";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
4
|
+
import { IntlayerPrunePlugin } from "./intlayerPrunePlugin.mjs";
|
|
5
|
+
const intlayerPlugin = (pluginOptions = {}) => {
|
|
6
|
+
const { enableBabelTransform = process.env.NODE_ENV === "production" } = pluginOptions;
|
|
7
|
+
const plugins = [
|
|
8
|
+
{
|
|
9
|
+
name: "vite-intlayer-plugin",
|
|
10
|
+
config: (config) => {
|
|
11
|
+
const intlayerConfig = getConfiguration();
|
|
12
|
+
const {
|
|
13
|
+
mainDir,
|
|
14
|
+
configDir,
|
|
15
|
+
baseDir,
|
|
16
|
+
watch: isWatchMode
|
|
17
|
+
} = intlayerConfig.content;
|
|
18
|
+
const dictionariesPath = join(mainDir, "dictionaries.mjs");
|
|
19
|
+
const relativeDictionariesPath = relative(baseDir, dictionariesPath);
|
|
20
|
+
const unmergedDictionariesPath = join(
|
|
21
|
+
mainDir,
|
|
22
|
+
"unmerged_dictionaries.mjs"
|
|
23
|
+
);
|
|
24
|
+
const relativeUnmergedDictionariesPath = relative(
|
|
25
|
+
baseDir,
|
|
26
|
+
unmergedDictionariesPath
|
|
27
|
+
);
|
|
28
|
+
const configurationPath = join(configDir, "configuration.json");
|
|
29
|
+
const relativeConfigurationPath = relative(baseDir, configurationPath);
|
|
30
|
+
config.resolve = {
|
|
31
|
+
...config.resolve,
|
|
32
|
+
alias: {
|
|
33
|
+
...config.resolve?.alias,
|
|
34
|
+
"@intlayer/dictionaries-entry": resolve(relativeDictionariesPath),
|
|
35
|
+
"@intlayer/unmerged-dictionaries-entry": resolve(
|
|
36
|
+
relativeUnmergedDictionariesPath
|
|
37
|
+
),
|
|
38
|
+
"@intlayer/config/built": resolve(relativeConfigurationPath)
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
if (isWatchMode) {
|
|
42
|
+
config.optimizeDeps = {
|
|
43
|
+
...config.optimizeDeps,
|
|
44
|
+
exclude: [
|
|
45
|
+
...config.optimizeDeps?.exclude ?? [],
|
|
46
|
+
"@intlayer/dictionaries-entry",
|
|
47
|
+
"@intlayer/unmerged-dictionaries-entry",
|
|
48
|
+
"@intlayer/config/built"
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return config;
|
|
53
|
+
},
|
|
54
|
+
configureServer: async () => {
|
|
55
|
+
const intlayerConfig = getConfiguration();
|
|
56
|
+
if (intlayerConfig.content.watch) {
|
|
57
|
+
watch({ configuration: intlayerConfig });
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
buildStart: async () => {
|
|
61
|
+
const intlayerConfig = getConfiguration();
|
|
62
|
+
await prepareIntlayer(intlayerConfig);
|
|
32
63
|
}
|
|
33
|
-
};
|
|
34
|
-
if (isWatchMode) {
|
|
35
|
-
config.optimizeDeps = {
|
|
36
|
-
...config.optimizeDeps,
|
|
37
|
-
exclude: [
|
|
38
|
-
...config.optimizeDeps?.exclude ?? [],
|
|
39
|
-
"@intlayer/dictionaries-entry",
|
|
40
|
-
"@intlayer/unmerged-dictionaries-entry",
|
|
41
|
-
"@intlayer/config/built"
|
|
42
|
-
]
|
|
43
|
-
};
|
|
44
64
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const intlayerConfig = getConfiguration();
|
|
49
|
-
if (intlayerConfig.content.watch) {
|
|
50
|
-
watch({ configuration: intlayerConfig });
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
buildStart: async () => {
|
|
54
|
-
const intlayerConfig = getConfiguration();
|
|
55
|
-
await prepareIntlayer(intlayerConfig);
|
|
65
|
+
];
|
|
66
|
+
if (enableBabelTransform) {
|
|
67
|
+
plugins.push(IntlayerPrunePlugin());
|
|
56
68
|
}
|
|
57
|
-
|
|
69
|
+
return plugins;
|
|
70
|
+
};
|
|
58
71
|
export {
|
|
59
72
|
intlayerPlugin
|
|
60
73
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport { join, relative, resolve } from 'path';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { type PluginOption } from 'vite';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n};\n\n/**\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerPlugin() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { prepareIntlayer, watch } from '@intlayer/chokidar';\nimport { getConfiguration } from '@intlayer/config';\nimport { join, relative, resolve } from 'path';\n// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { type PluginOption } from 'vite';\nimport { IntlayerPrunePlugin } from './intlayerPrunePlugin';\n\n// Plugin options type definition\ntype PluginOptions = {\n // Custom options for your plugin, if any\n enableBabelTransform?: boolean;\n};\n\n/**\n *\n * A Vite plugin that integrates Intlayer configuration into the build process\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerPlugin() ],\n * });\n * ```\n * */\nexport const intlayerPlugin = (\n pluginOptions: PluginOptions = {}\n): PluginOption => {\n const { enableBabelTransform = process.env.NODE_ENV === 'production' } =\n pluginOptions;\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: (config) => {\n const intlayerConfig = getConfiguration();\n const {\n mainDir,\n configDir,\n baseDir,\n watch: isWatchMode,\n } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n const unmergedDictionariesPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n const relativeUnmergedDictionariesPath = relative(\n baseDir,\n unmergedDictionariesPath\n );\n\n const configurationPath = join(configDir, 'configuration.json');\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n\n // Update Vite's resolve alias\n config.resolve = {\n ...config.resolve,\n alias: {\n ...config.resolve?.alias,\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n '@intlayer/unmerged-dictionaries-entry': resolve(\n relativeUnmergedDictionariesPath\n ),\n '@intlayer/config/built': resolve(relativeConfigurationPath),\n },\n };\n\n if (isWatchMode) {\n // Ajout de l'option optimizeDeps.exclude\n config.optimizeDeps = {\n ...config.optimizeDeps,\n exclude: [\n ...(config.optimizeDeps?.exclude ?? []),\n '@intlayer/dictionaries-entry',\n '@intlayer/unmerged-dictionaries-entry',\n '@intlayer/config/built',\n ],\n };\n }\n\n return config;\n },\n\n configureServer: async () => {\n // Runs when the dev server starts\n const intlayerConfig = getConfiguration();\n\n if (intlayerConfig.content.watch) {\n // Start watching (assuming watch is also async)\n watch({ configuration: intlayerConfig });\n }\n },\n\n buildStart: async () => {\n // Code to run when Vite build starts\n const intlayerConfig = getConfiguration();\n await prepareIntlayer(intlayerConfig);\n },\n },\n ];\n\n // Add Babel transform plugin if enabled\n if (enableBabelTransform) {\n plugins.push(IntlayerPrunePlugin());\n }\n\n return plugins;\n};\n"],"mappings":"AAAA,SAAS,iBAAiB,aAAa;AACvC,SAAS,wBAAwB;AACjC,SAAS,MAAM,UAAU,eAAe;AAGxC,SAAS,2BAA2B;AAmB7B,MAAM,iBAAiB,CAC5B,gBAA+B,CAAC,MACf;AACjB,QAAM,EAAE,uBAAuB,QAAQ,IAAI,aAAa,aAAa,IACnE;AAEF,QAAM,UAA0B;AAAA,IAC9B;AAAA,MACE,MAAM;AAAA,MAEN,QAAQ,CAAC,WAAW;AAClB,cAAM,iBAAiB,iBAAiB;AACxC,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA,OAAO;AAAA,QACT,IAAI,eAAe;AAEnB,cAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,cAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAEnE,cAAM,2BAA2B;AAAA,UAC/B;AAAA,UACA;AAAA,QACF;AACA,cAAM,mCAAmC;AAAA,UACvC;AAAA,UACA;AAAA,QACF;AAEA,cAAM,oBAAoB,KAAK,WAAW,oBAAoB;AAC9D,cAAM,4BAA4B,SAAS,SAAS,iBAAiB;AAGrE,eAAO,UAAU;AAAA,UACf,GAAG,OAAO;AAAA,UACV,OAAO;AAAA,YACL,GAAG,OAAO,SAAS;AAAA,YACnB,gCAAgC,QAAQ,wBAAwB;AAAA,YAChE,yCAAyC;AAAA,cACvC;AAAA,YACF;AAAA,YACA,0BAA0B,QAAQ,yBAAyB;AAAA,UAC7D;AAAA,QACF;AAEA,YAAI,aAAa;AAEf,iBAAO,eAAe;AAAA,YACpB,GAAG,OAAO;AAAA,YACV,SAAS;AAAA,cACP,GAAI,OAAO,cAAc,WAAW,CAAC;AAAA,cACrC;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,eAAO;AAAA,MACT;AAAA,MAEA,iBAAiB,YAAY;AAE3B,cAAM,iBAAiB,iBAAiB;AAExC,YAAI,eAAe,QAAQ,OAAO;AAEhC,gBAAM,EAAE,eAAe,eAAe,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,MAEA,YAAY,YAAY;AAEtB,cAAM,iBAAiB,iBAAiB;AACxC,cAAM,gBAAgB,cAAc;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAGA,MAAI,sBAAsB;AACxB,YAAQ,KAAK,oBAAoB,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { babelPluginIntlayer } from "@intlayer/babel";
|
|
2
|
+
import { ESMxCJSRequire } from "@intlayer/config";
|
|
3
|
+
const IntlayerPrunePlugin = () => ({
|
|
4
|
+
name: "vite-intlayer-babel-transform",
|
|
5
|
+
transform(code, id) {
|
|
6
|
+
const fileExtensionPattern = /\.(tsx?|jsx?|vue|svelte|cjs|mjs|js|cjx|mjx)$/;
|
|
7
|
+
if (!fileExtensionPattern.test(id)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (!code.includes("useIntlayer")) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const babel = ESMxCJSRequire("@babel/core");
|
|
15
|
+
const result = babel.transformSync(code, {
|
|
16
|
+
filename: id,
|
|
17
|
+
plugins: [babelPluginIntlayer],
|
|
18
|
+
parserOpts: {
|
|
19
|
+
sourceType: "module",
|
|
20
|
+
allowImportExportEverywhere: true,
|
|
21
|
+
plugins: [
|
|
22
|
+
"typescript",
|
|
23
|
+
"jsx",
|
|
24
|
+
"decorators-legacy",
|
|
25
|
+
"classProperties",
|
|
26
|
+
"objectRestSpread",
|
|
27
|
+
"asyncGenerators",
|
|
28
|
+
"functionBind",
|
|
29
|
+
"exportDefaultFrom",
|
|
30
|
+
"exportNamespaceFrom",
|
|
31
|
+
"dynamicImport",
|
|
32
|
+
"nullishCoalescingOperator",
|
|
33
|
+
"optionalChaining"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (result?.code) {
|
|
38
|
+
return {
|
|
39
|
+
code: result.code,
|
|
40
|
+
map: result.map
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.warn("Failed to transform with Babel plugin:", error);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
export {
|
|
50
|
+
IntlayerPrunePlugin
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=intlayerPrunePlugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { babelPluginIntlayer } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => ({\n name: 'vite-intlayer-babel-transform',\n transform(code, id) {\n // Only transform React/TypeScript files\n const fileExtensionPattern = /\\.(tsx?|jsx?|vue|svelte|cjs|mjs|js|cjx|mjx)$/;\n if (!fileExtensionPattern.test(id)) {\n return null;\n }\n\n // Only transform files that contain useIntlayer\n if (!code.includes('useIntlayer')) {\n return null;\n }\n\n try {\n const babel = ESMxCJSRequire('@babel/core');\n const result = babel.transformSync(code, {\n filename: id,\n plugins: [babelPluginIntlayer],\n parserOpts: {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n },\n });\n\n if (result?.code) {\n return {\n code: result.code,\n map: result.map,\n };\n }\n } catch (error) {\n console.warn('Failed to transform with Babel plugin:', error);\n }\n\n return null;\n },\n});\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAGxB,MAAM,sBAAsB,OAAqB;AAAA,EACtD,MAAM;AAAA,EACN,UAAU,MAAM,IAAI;AAElB,UAAM,uBAAuB;AAC7B,QAAI,CAAC,qBAAqB,KAAK,EAAE,GAAG;AAClC,aAAO;AAAA,IACT;AAGA,QAAI,CAAC,KAAK,SAAS,aAAa,GAAG;AACjC,aAAO;AAAA,IACT;AAEA,QAAI;AACF,YAAM,QAAQ,eAAe,aAAa;AAC1C,YAAM,SAAS,MAAM,cAAc,MAAM;AAAA,QACvC,UAAU;AAAA,QACV,SAAS,CAAC,mBAAmB;AAAA,QAC7B,YAAY;AAAA,UACV,YAAY;AAAA,UACZ,6BAA6B;AAAA,UAC7B,SAAS;AAAA,YACP;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAED,UAAI,QAAQ,MAAM;AAChB,eAAO;AAAA,UACL,MAAM,OAAO;AAAA,UACb,KAAK,OAAO;AAAA,QACd;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,cAAQ,KAAK,0CAA0C,KAAK;AAAA,IAC9D;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type PluginOption } from 'vite';
|
|
2
|
-
type PluginOptions = {
|
|
2
|
+
type PluginOptions = {
|
|
3
|
+
enableBabelTransform?: boolean;
|
|
4
|
+
};
|
|
3
5
|
/**
|
|
4
6
|
*
|
|
5
7
|
* A Vite plugin that integrates Intlayer configuration into the build process
|
|
@@ -11,6 +13,6 @@ type PluginOptions = {};
|
|
|
11
13
|
* });
|
|
12
14
|
* ```
|
|
13
15
|
* */
|
|
14
|
-
export declare const intlayerPlugin: (
|
|
16
|
+
export declare const intlayerPlugin: (pluginOptions?: PluginOptions) => PluginOption;
|
|
15
17
|
export {};
|
|
16
18
|
//# sourceMappingURL=intlayerPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPlugin.d.ts","sourceRoot":"","sources":["../../src/intlayerPlugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"intlayerPlugin.d.ts","sourceRoot":"","sources":["../../src/intlayerPlugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAIzC,KAAK,aAAa,GAAG;IAEnB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF;;;;;;;;;;MAUM;AACN,eAAO,MAAM,cAAc,GACzB,gBAAe,aAAkB,KAChC,YAqFF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intlayerPrunePlugin.d.ts","sourceRoot":"","sources":["../../src/intlayerPrunePlugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,eAAO,MAAM,mBAAmB,QAAO,YAmDrC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-intlayer",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -58,9 +58,10 @@
|
|
|
58
58
|
"./package.json"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@intlayer/
|
|
62
|
-
"@intlayer/
|
|
63
|
-
"@intlayer/core": "5.5.
|
|
61
|
+
"@intlayer/babel": "5.5.2",
|
|
62
|
+
"@intlayer/chokidar": "5.5.2",
|
|
63
|
+
"@intlayer/core": "5.5.2",
|
|
64
|
+
"@intlayer/config": "5.5.2"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
67
|
"@types/node": "^22.13.10",
|
|
@@ -73,15 +74,15 @@
|
|
|
73
74
|
"tsup": "^8.4.0",
|
|
74
75
|
"typescript": "^5.8.2",
|
|
75
76
|
"@utils/eslint-config": "1.0.4",
|
|
77
|
+
"@utils/ts-config": "1.0.4",
|
|
76
78
|
"@utils/ts-config-types": "1.0.4",
|
|
77
|
-
"@utils/tsup-config": "1.0.4"
|
|
78
|
-
"@utils/ts-config": "1.0.4"
|
|
79
|
+
"@utils/tsup-config": "1.0.4"
|
|
79
80
|
},
|
|
80
81
|
"peerDependencies": {
|
|
81
82
|
"vite": ">=4.0.0",
|
|
82
|
-
"@intlayer/chokidar": "5.5.
|
|
83
|
-
"@intlayer/config": "5.5.
|
|
84
|
-
"@intlayer/core": "5.5.
|
|
83
|
+
"@intlayer/chokidar": "5.5.2",
|
|
84
|
+
"@intlayer/config": "5.5.2",
|
|
85
|
+
"@intlayer/core": "5.5.2"
|
|
85
86
|
},
|
|
86
87
|
"engines": {
|
|
87
88
|
"node": ">=14.18"
|