vite-intlayer 5.5.3 → 5.5.4
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/dist/cjs/intlayerPlugin.cjs +14 -16
- package/dist/cjs/intlayerPlugin.cjs.map +1 -1
- package/dist/cjs/intlayerPrunePlugin.cjs +69 -56
- package/dist/cjs/intlayerPrunePlugin.cjs.map +1 -1
- package/dist/esm/intlayerPlugin.mjs +14 -16
- package/dist/esm/intlayerPlugin.mjs.map +1 -1
- package/dist/esm/intlayerPrunePlugin.mjs +69 -56
- package/dist/esm/intlayerPrunePlugin.mjs.map +1 -1
- package/dist/types/intlayerPlugin.d.ts +1 -5
- package/dist/types/intlayerPlugin.d.ts.map +1 -1
- package/dist/types/intlayerPrunePlugin.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -27,20 +27,18 @@ var import_path = require("path");
|
|
|
27
27
|
var import_intlayerPrunePlugin = require('./intlayerPrunePlugin.cjs');
|
|
28
28
|
(0, import_chokidar.cleanOutputDir)();
|
|
29
29
|
const intlayerPlugin = (pluginOptions = {}) => {
|
|
30
|
-
const
|
|
30
|
+
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
31
|
+
const {
|
|
32
|
+
mainDir,
|
|
33
|
+
configDir,
|
|
34
|
+
baseDir,
|
|
35
|
+
watch: isWatchMode
|
|
36
|
+
} = intlayerConfig.content;
|
|
37
|
+
const { optimize } = intlayerConfig.build;
|
|
31
38
|
const plugins = [
|
|
32
39
|
{
|
|
33
40
|
name: "vite-intlayer-plugin",
|
|
34
41
|
config: (config) => {
|
|
35
|
-
const intlayerConfig = (0, import_config.getConfiguration)();
|
|
36
|
-
const {
|
|
37
|
-
dictionariesDir,
|
|
38
|
-
mainDir,
|
|
39
|
-
configDir,
|
|
40
|
-
typesDir,
|
|
41
|
-
baseDir,
|
|
42
|
-
watch: isWatchMode
|
|
43
|
-
} = intlayerConfig.content;
|
|
44
42
|
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
|
|
45
43
|
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
46
44
|
const unmergedDictionariesPath = (0, import_path.join)(
|
|
@@ -78,18 +76,18 @@ const intlayerPlugin = (pluginOptions = {}) => {
|
|
|
78
76
|
return config;
|
|
79
77
|
},
|
|
80
78
|
configureServer: async (server) => {
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
(0, import_chokidar.watch)({ configuration:
|
|
79
|
+
const intlayerConfig2 = (0, import_config.getConfiguration)();
|
|
80
|
+
if (intlayerConfig2.content.watch) {
|
|
81
|
+
(0, import_chokidar.watch)({ configuration: intlayerConfig2 });
|
|
84
82
|
}
|
|
85
83
|
},
|
|
86
84
|
buildStart: async () => {
|
|
87
|
-
const
|
|
88
|
-
await (0, import_chokidar.prepareIntlayer)(
|
|
85
|
+
const intlayerConfig2 = (0, import_config.getConfiguration)();
|
|
86
|
+
await (0, import_chokidar.prepareIntlayer)(intlayerConfig2);
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
];
|
|
92
|
-
if (
|
|
90
|
+
if (optimize) {
|
|
93
91
|
plugins.push((0, import_intlayerPrunePlugin.IntlayerPrunePlugin)());
|
|
94
92
|
}
|
|
95
93
|
return plugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { cleanOutputDir, 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\
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { cleanOutputDir, 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\ncleanOutputDir();\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 = (pluginOptions = {}): PluginOption => {\n const intlayerConfig = getConfiguration();\n const {\n mainDir,\n configDir,\n baseDir,\n watch: isWatchMode,\n } = intlayerConfig.content;\n const { optimize } = intlayerConfig.build;\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: (config) => {\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 (server) => {\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 (optimize) {\n plugins.push(IntlayerPrunePlugin());\n }\n\n return plugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAuD;AACvD,oBAAiC;AACjC,kBAAwC;AAGxC,iCAAoC;AAAA,IAEpC,gCAAe;AAaR,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,MAAoB;AAClE,QAAM,qBAAiB,gCAAiB;AACxC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,EACT,IAAI,eAAe;AACnB,QAAM,EAAE,SAAS,IAAI,eAAe;AAEpC,QAAM,UAA0B;AAAA,IAC9B;AAAA,MACE,MAAM;AAAA,MAEN,QAAQ,CAAC,WAAW;AAClB,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,OAAO,WAAW;AAEjC,cAAMA,sBAAiB,gCAAiB;AAExC,YAAIA,gBAAe,QAAQ,OAAO;AAEhC,qCAAM,EAAE,eAAeA,gBAAe,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,MAEA,YAAY,YAAY;AAEtB,cAAMA,sBAAiB,gCAAiB;AACxC,kBAAM,iCAAgBA,eAAc;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAGA,MAAI,UAAU;AACZ,YAAQ,SAAK,gDAAoB,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":["intlayerConfig"]}
|
|
@@ -34,68 +34,81 @@ module.exports = __toCommonJS(intlayerPrunePlugin_exports);
|
|
|
34
34
|
var import_babel = require("@intlayer/babel");
|
|
35
35
|
var import_config = require("@intlayer/config");
|
|
36
36
|
var import_built = __toESM(require("@intlayer/config/built"));
|
|
37
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
37
38
|
var import_path = require("path");
|
|
38
|
-
const IntlayerPrunePlugin = () =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
"
|
|
39
|
+
const IntlayerPrunePlugin = () => {
|
|
40
|
+
const { optimize, activateDynamicImport, traversePattern } = import_built.default.build;
|
|
41
|
+
const { dictionariesDir, dynamicDictionariesDir, mainDir, baseDir } = import_built.default.content;
|
|
42
|
+
const filesListPattern = import_fast_glob.default.sync(traversePattern, {
|
|
43
|
+
cwd: baseDir
|
|
44
|
+
}).map((file) => (0, import_path.join)(baseDir, file));
|
|
45
|
+
return {
|
|
46
|
+
name: "vite-intlayer-babel-transform",
|
|
47
|
+
enforce: "post",
|
|
48
|
+
// Run after other transformations as vue
|
|
49
|
+
transform(code, id) {
|
|
50
|
+
const dictionariesEntryPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
|
|
51
|
+
const dynamicDictionariesEntryPath = (0, import_path.join)(
|
|
52
|
+
mainDir,
|
|
53
|
+
"dynamic_dictionaries.mjs"
|
|
53
54
|
);
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
]
|
|
67
|
-
],
|
|
68
|
-
parserOpts: {
|
|
69
|
-
sourceType: "module",
|
|
70
|
-
allowImportExportEverywhere: true,
|
|
55
|
+
const filesList = [
|
|
56
|
+
...filesListPattern,
|
|
57
|
+
dictionariesEntryPath
|
|
58
|
+
// should add dictionariesEntryPath to replace it by a empty object if import made dynamic
|
|
59
|
+
];
|
|
60
|
+
const filename = id.split("?", 1)[0];
|
|
61
|
+
if (!filesList.includes(filename)) return null;
|
|
62
|
+
if (!optimize) return null;
|
|
63
|
+
try {
|
|
64
|
+
const babel = (0, import_config.ESMxCJSRequire)("@babel/core");
|
|
65
|
+
const result = babel.transformSync(code, {
|
|
66
|
+
filename,
|
|
71
67
|
plugins: [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
[
|
|
69
|
+
import_babel.intlayerBabelPlugin,
|
|
70
|
+
{
|
|
71
|
+
dictionariesDir,
|
|
72
|
+
dictionariesEntryPath,
|
|
73
|
+
dynamicDictionariesDir,
|
|
74
|
+
dynamicDictionariesEntryPath,
|
|
75
|
+
activateDynamicImport,
|
|
76
|
+
filesList
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
],
|
|
80
|
+
parserOpts: {
|
|
81
|
+
sourceType: "module",
|
|
82
|
+
allowImportExportEverywhere: true,
|
|
83
|
+
plugins: [
|
|
84
|
+
"typescript",
|
|
85
|
+
"jsx",
|
|
86
|
+
"decorators-legacy",
|
|
87
|
+
"classProperties",
|
|
88
|
+
"objectRestSpread",
|
|
89
|
+
"asyncGenerators",
|
|
90
|
+
"functionBind",
|
|
91
|
+
"exportDefaultFrom",
|
|
92
|
+
"exportNamespaceFrom",
|
|
93
|
+
"dynamicImport",
|
|
94
|
+
"nullishCoalescingOperator",
|
|
95
|
+
"optionalChaining"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
if (result?.code) {
|
|
100
|
+
return {
|
|
101
|
+
code: result.code,
|
|
102
|
+
map: result.map
|
|
103
|
+
};
|
|
85
104
|
}
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
code: result.code,
|
|
90
|
-
map: result.map
|
|
91
|
-
};
|
|
105
|
+
} catch (error) {
|
|
106
|
+
console.warn("Failed to transform with Babel plugin:", error);
|
|
92
107
|
}
|
|
93
|
-
|
|
94
|
-
console.warn("Failed to transform with Babel plugin:", error);
|
|
108
|
+
return null;
|
|
95
109
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
110
|
+
};
|
|
111
|
+
};
|
|
99
112
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
113
|
0 && (module.exports = {
|
|
101
114
|
IntlayerPrunePlugin
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { join } from 'path';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => ({\n name: 'vite-intlayer-babel-transform',\n
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport fg from 'fast-glob';\nimport { join } from 'path';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => {\n const { optimize, activateDynamicImport, traversePattern } =\n configuration.build;\n const { dictionariesDir, dynamicDictionariesDir, mainDir, baseDir } =\n configuration.content;\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n return {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after other transformations as vue\n transform(code, id) {\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n /**\n * Transform file as\n * .../HelloWorld.vue?vue&type=script&setup=true&lang.ts\n * Into\n * .../HelloWorld.vue\n *\n * Prevention for virtual file\n */\n const filename = id.split('?', 1)[0];\n if (!filesList.includes(filename)) return null;\n if (!optimize) return null;\n\n try {\n const babel = ESMxCJSRequire('@babel/core');\n\n const result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n activateDynamicImport,\n filesList,\n },\n ],\n ],\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};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAoC;AACpC,oBAA+B;AAC/B,mBAA0B;AAC1B,uBAAe;AACf,kBAAqB;AAGd,MAAM,sBAAsB,MAAoB;AACrD,QAAM,EAAE,UAAU,uBAAuB,gBAAgB,IACvD,aAAAA,QAAc;AAChB,QAAM,EAAE,iBAAiB,wBAAwB,SAAS,QAAQ,IAChE,aAAAA,QAAc;AAEhB,QAAM,mBAAmB,iBAAAC,QACtB,KAAK,iBAAiB;AAAA,IACrB,KAAK;AAAA,EACP,CAAC,EACA,IAAI,CAAC,aAAS,kBAAK,SAAS,IAAI,CAAC;AAEpC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,IACT,UAAU,MAAM,IAAI;AAClB,YAAM,4BAAwB,kBAAK,SAAS,kBAAkB;AAC9D,YAAM,mCAA+B;AAAA,QACnC;AAAA,QACA;AAAA,MACF;AAEA,YAAM,YAAY;AAAA,QAChB,GAAG;AAAA,QACH;AAAA;AAAA,MACF;AAUA,YAAM,WAAW,GAAG,MAAM,KAAK,CAAC,EAAE,CAAC;AACnC,UAAI,CAAC,UAAU,SAAS,QAAQ,EAAG,QAAO;AAC1C,UAAI,CAAC,SAAU,QAAO;AAEtB,UAAI;AACF,cAAM,YAAQ,8BAAe,aAAa;AAE1C,cAAM,SAAS,MAAM,cAAc,MAAM;AAAA,UACvC;AAAA,UACA,SAAS;AAAA,YACP;AAAA,cACE;AAAA,cACA;AAAA,gBACE;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA,YAAY;AAAA,YACV,YAAY;AAAA,YACZ,6BAA6B;AAAA,YAC7B,SAAS;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AAED,YAAI,QAAQ,MAAM;AAChB,iBAAO;AAAA,YACL,MAAM,OAAO;AAAA,YACb,KAAK,OAAO;AAAA,UACd;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,gBAAQ,KAAK,0CAA0C,KAAK;AAAA,MAC9D;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["configuration","fg"]}
|
|
@@ -4,20 +4,18 @@ import { join, relative, resolve } from "path";
|
|
|
4
4
|
import { IntlayerPrunePlugin } from "./intlayerPrunePlugin.mjs";
|
|
5
5
|
cleanOutputDir();
|
|
6
6
|
const intlayerPlugin = (pluginOptions = {}) => {
|
|
7
|
-
const
|
|
7
|
+
const intlayerConfig = getConfiguration();
|
|
8
|
+
const {
|
|
9
|
+
mainDir,
|
|
10
|
+
configDir,
|
|
11
|
+
baseDir,
|
|
12
|
+
watch: isWatchMode
|
|
13
|
+
} = intlayerConfig.content;
|
|
14
|
+
const { optimize } = intlayerConfig.build;
|
|
8
15
|
const plugins = [
|
|
9
16
|
{
|
|
10
17
|
name: "vite-intlayer-plugin",
|
|
11
18
|
config: (config) => {
|
|
12
|
-
const intlayerConfig = getConfiguration();
|
|
13
|
-
const {
|
|
14
|
-
dictionariesDir,
|
|
15
|
-
mainDir,
|
|
16
|
-
configDir,
|
|
17
|
-
typesDir,
|
|
18
|
-
baseDir,
|
|
19
|
-
watch: isWatchMode
|
|
20
|
-
} = intlayerConfig.content;
|
|
21
19
|
const dictionariesPath = join(mainDir, "dictionaries.mjs");
|
|
22
20
|
const relativeDictionariesPath = relative(baseDir, dictionariesPath);
|
|
23
21
|
const unmergedDictionariesPath = join(
|
|
@@ -55,18 +53,18 @@ const intlayerPlugin = (pluginOptions = {}) => {
|
|
|
55
53
|
return config;
|
|
56
54
|
},
|
|
57
55
|
configureServer: async (server) => {
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
watch({ configuration:
|
|
56
|
+
const intlayerConfig2 = getConfiguration();
|
|
57
|
+
if (intlayerConfig2.content.watch) {
|
|
58
|
+
watch({ configuration: intlayerConfig2 });
|
|
61
59
|
}
|
|
62
60
|
},
|
|
63
61
|
buildStart: async () => {
|
|
64
|
-
const
|
|
65
|
-
await prepareIntlayer(
|
|
62
|
+
const intlayerConfig2 = getConfiguration();
|
|
63
|
+
await prepareIntlayer(intlayerConfig2);
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
];
|
|
69
|
-
if (
|
|
67
|
+
if (optimize) {
|
|
70
68
|
plugins.push(IntlayerPrunePlugin());
|
|
71
69
|
}
|
|
72
70
|
return plugins;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { cleanOutputDir, 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\
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPlugin.ts"],"sourcesContent":["import { cleanOutputDir, 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\ncleanOutputDir();\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 = (pluginOptions = {}): PluginOption => {\n const intlayerConfig = getConfiguration();\n const {\n mainDir,\n configDir,\n baseDir,\n watch: isWatchMode,\n } = intlayerConfig.content;\n const { optimize } = intlayerConfig.build;\n\n const plugins: PluginOption[] = [\n {\n name: 'vite-intlayer-plugin',\n\n config: (config) => {\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 (server) => {\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 (optimize) {\n plugins.push(IntlayerPrunePlugin());\n }\n\n return plugins;\n};\n"],"mappings":"AAAA,SAAS,gBAAgB,iBAAiB,aAAa;AACvD,SAAS,wBAAwB;AACjC,SAAS,MAAM,UAAU,eAAe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,iBAAiB;AACxC,cAAM,gBAAgBA,eAAc;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AAGA,MAAI,UAAU;AACZ,YAAQ,KAAK,oBAAoB,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":["intlayerConfig"]}
|
|
@@ -1,68 +1,81 @@
|
|
|
1
1
|
import { intlayerBabelPlugin } from "@intlayer/babel";
|
|
2
2
|
import { ESMxCJSRequire } from "@intlayer/config";
|
|
3
3
|
import configuration from "@intlayer/config/built";
|
|
4
|
+
import fg from "fast-glob";
|
|
4
5
|
import { join } from "path";
|
|
5
|
-
const IntlayerPrunePlugin = () =>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
"
|
|
6
|
+
const IntlayerPrunePlugin = () => {
|
|
7
|
+
const { optimize, activateDynamicImport, traversePattern } = configuration.build;
|
|
8
|
+
const { dictionariesDir, dynamicDictionariesDir, mainDir, baseDir } = configuration.content;
|
|
9
|
+
const filesListPattern = fg.sync(traversePattern, {
|
|
10
|
+
cwd: baseDir
|
|
11
|
+
}).map((file) => join(baseDir, file));
|
|
12
|
+
return {
|
|
13
|
+
name: "vite-intlayer-babel-transform",
|
|
14
|
+
enforce: "post",
|
|
15
|
+
// Run after other transformations as vue
|
|
16
|
+
transform(code, id) {
|
|
17
|
+
const dictionariesEntryPath = join(mainDir, "dictionaries.mjs");
|
|
18
|
+
const dynamicDictionariesEntryPath = join(
|
|
19
|
+
mainDir,
|
|
20
|
+
"dynamic_dictionaries.mjs"
|
|
20
21
|
);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
]
|
|
34
|
-
],
|
|
35
|
-
parserOpts: {
|
|
36
|
-
sourceType: "module",
|
|
37
|
-
allowImportExportEverywhere: true,
|
|
22
|
+
const filesList = [
|
|
23
|
+
...filesListPattern,
|
|
24
|
+
dictionariesEntryPath
|
|
25
|
+
// should add dictionariesEntryPath to replace it by a empty object if import made dynamic
|
|
26
|
+
];
|
|
27
|
+
const filename = id.split("?", 1)[0];
|
|
28
|
+
if (!filesList.includes(filename)) return null;
|
|
29
|
+
if (!optimize) return null;
|
|
30
|
+
try {
|
|
31
|
+
const babel = ESMxCJSRequire("@babel/core");
|
|
32
|
+
const result = babel.transformSync(code, {
|
|
33
|
+
filename,
|
|
38
34
|
plugins: [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
[
|
|
36
|
+
intlayerBabelPlugin,
|
|
37
|
+
{
|
|
38
|
+
dictionariesDir,
|
|
39
|
+
dictionariesEntryPath,
|
|
40
|
+
dynamicDictionariesDir,
|
|
41
|
+
dynamicDictionariesEntryPath,
|
|
42
|
+
activateDynamicImport,
|
|
43
|
+
filesList
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
],
|
|
47
|
+
parserOpts: {
|
|
48
|
+
sourceType: "module",
|
|
49
|
+
allowImportExportEverywhere: true,
|
|
50
|
+
plugins: [
|
|
51
|
+
"typescript",
|
|
52
|
+
"jsx",
|
|
53
|
+
"decorators-legacy",
|
|
54
|
+
"classProperties",
|
|
55
|
+
"objectRestSpread",
|
|
56
|
+
"asyncGenerators",
|
|
57
|
+
"functionBind",
|
|
58
|
+
"exportDefaultFrom",
|
|
59
|
+
"exportNamespaceFrom",
|
|
60
|
+
"dynamicImport",
|
|
61
|
+
"nullishCoalescingOperator",
|
|
62
|
+
"optionalChaining"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (result?.code) {
|
|
67
|
+
return {
|
|
68
|
+
code: result.code,
|
|
69
|
+
map: result.map
|
|
70
|
+
};
|
|
52
71
|
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
code: result.code,
|
|
57
|
-
map: result.map
|
|
58
|
-
};
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.warn("Failed to transform with Babel plugin:", error);
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
console.warn("Failed to transform with Babel plugin:", error);
|
|
75
|
+
return null;
|
|
62
76
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
77
|
+
};
|
|
78
|
+
};
|
|
66
79
|
export {
|
|
67
80
|
IntlayerPrunePlugin
|
|
68
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { join } from 'path';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => ({\n name: 'vite-intlayer-babel-transform',\n
|
|
1
|
+
{"version":3,"sources":["../../src/intlayerPrunePlugin.ts"],"sourcesContent":["// @ts-ignore - Fix error Module '\"vite\"' has no exported member\nimport { intlayerBabelPlugin } from '@intlayer/babel';\nimport { ESMxCJSRequire } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport fg from 'fast-glob';\nimport { join } from 'path';\nimport { type PluginOption } from 'vite';\n\nexport const IntlayerPrunePlugin = (): PluginOption => {\n const { optimize, activateDynamicImport, traversePattern } =\n configuration.build;\n const { dictionariesDir, dynamicDictionariesDir, mainDir, baseDir } =\n configuration.content;\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n return {\n name: 'vite-intlayer-babel-transform',\n enforce: 'post', // Run after other transformations as vue\n transform(code, id) {\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n /**\n * Transform file as\n * .../HelloWorld.vue?vue&type=script&setup=true&lang.ts\n * Into\n * .../HelloWorld.vue\n *\n * Prevention for virtual file\n */\n const filename = id.split('?', 1)[0];\n if (!filesList.includes(filename)) return null;\n if (!optimize) return null;\n\n try {\n const babel = ESMxCJSRequire('@babel/core');\n\n const result = babel.transformSync(code, {\n filename,\n plugins: [\n [\n intlayerBabelPlugin,\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n activateDynamicImport,\n filesList,\n },\n ],\n ],\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};\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,QAAQ;AACf,SAAS,YAAY;AAGd,MAAM,sBAAsB,MAAoB;AACrD,QAAM,EAAE,UAAU,uBAAuB,gBAAgB,IACvD,cAAc;AAChB,QAAM,EAAE,iBAAiB,wBAAwB,SAAS,QAAQ,IAChE,cAAc;AAEhB,QAAM,mBAAmB,GACt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ption } from 'vite';
|
|
2
|
-
type PluginOptions = {
|
|
3
|
-
enableBabelTransform?: boolean;
|
|
4
|
-
};
|
|
5
2
|
/**
|
|
6
3
|
*
|
|
7
4
|
* A Vite plugin that integrates Intlayer configuration into the build process
|
|
@@ -13,6 +10,5 @@ type PluginOptions = {
|
|
|
13
10
|
* });
|
|
14
11
|
* ```
|
|
15
12
|
* */
|
|
16
|
-
export declare const intlayerPlugin: (pluginOptions?:
|
|
17
|
-
export {};
|
|
13
|
+
export declare const intlayerPlugin: (pluginOptions?: {}) => PluginOption;
|
|
18
14
|
//# 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;AAKzC;;;;;;;;;;MAUM;AACN,eAAO,MAAM,cAAc,GAAI,kBAAkB,KAAG,YAmFnD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerPrunePlugin.d.ts","sourceRoot":"","sources":["../../src/intlayerPrunePlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"intlayerPrunePlugin.d.ts","sourceRoot":"","sources":["../../src/intlayerPrunePlugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,eAAO,MAAM,mBAAmB,QAAO,YA0FtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-intlayer",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.4",
|
|
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,10 +58,10 @@
|
|
|
58
58
|
"./package.json"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@intlayer/
|
|
62
|
-
"@intlayer/
|
|
63
|
-
"@intlayer/
|
|
64
|
-
"@intlayer/babel": "5.5.
|
|
61
|
+
"@intlayer/chokidar": "5.5.4",
|
|
62
|
+
"@intlayer/config": "5.5.4",
|
|
63
|
+
"@intlayer/core": "5.5.4",
|
|
64
|
+
"@intlayer/babel": "5.5.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/node": "^22.13.10",
|
|
@@ -73,16 +73,16 @@
|
|
|
73
73
|
"tsc-alias": "^1.8.11",
|
|
74
74
|
"tsup": "^8.4.0",
|
|
75
75
|
"typescript": "^5.8.2",
|
|
76
|
-
"@utils/ts-config": "1.0.4",
|
|
76
|
+
"@utils/ts-config-types": "1.0.4",
|
|
77
77
|
"@utils/eslint-config": "1.0.4",
|
|
78
78
|
"@utils/tsup-config": "1.0.4",
|
|
79
|
-
"@utils/ts-config
|
|
79
|
+
"@utils/ts-config": "1.0.4"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"vite": ">=4.0.0",
|
|
83
|
-
"@intlayer/
|
|
84
|
-
"@intlayer/
|
|
85
|
-
"@intlayer/core": "5.5.
|
|
83
|
+
"@intlayer/chokidar": "5.5.4",
|
|
84
|
+
"@intlayer/config": "5.5.4",
|
|
85
|
+
"@intlayer/core": "5.5.4"
|
|
86
86
|
},
|
|
87
87
|
"engines": {
|
|
88
88
|
"node": ">=14.18"
|