UNPKG

vite-intlayer

Version:

A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration

115 lines 4.47 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var intlayerPlugin_exports = {}; __export(intlayerPlugin_exports, { intlayerPlugin: () => intlayerPlugin }); module.exports = __toCommonJS(intlayerPlugin_exports); var import_chokidar = require("@intlayer/chokidar"); var import_built = __toESM(require("@intlayer/config/built")); var import_path = require("path"); var import_intlayerPrunePlugin = require('./intlayerPrunePlugin.cjs'); (0, import_chokidar.cleanOutputDir)(); const intlayerPlugin = () => { const { mainDir, configDir, baseDir, watch: isWatchMode } = import_built.default.content; const { optimize } = import_built.default.build; const plugins = [ { name: "vite-intlayer-plugin", config: (config) => { const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs"); const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath); const unmergedDictionariesPath = (0, import_path.join)( mainDir, "unmerged_dictionaries.mjs" ); const relativeUnmergedDictionariesPath = (0, import_path.relative)( baseDir, unmergedDictionariesPath ); const configurationPath = (0, import_path.join)(configDir, "configuration.json"); const relativeConfigurationPath = (0, import_path.relative)(baseDir, configurationPath); config.resolve = { ...config.resolve, alias: { ...config.resolve?.alias, "@intlayer/dictionaries-entry": (0, import_path.resolve)(relativeDictionariesPath), "@intlayer/unmerged-dictionaries-entry": (0, import_path.resolve)( relativeUnmergedDictionariesPath ), "@intlayer/config/built": (0, import_path.resolve)(relativeConfigurationPath) } }; if (isWatchMode) { config.optimizeDeps = { ...config.optimizeDeps, exclude: [ ...config.optimizeDeps?.exclude ?? [], "@intlayer/dictionaries-entry", "@intlayer/unmerged-dictionaries-entry", "@intlayer/config/built" ] }; } return config; }, configureServer: async (server) => { if (import_built.default.content.watch) { (0, import_chokidar.watch)({ configuration: import_built.default }); } }, buildStart: async () => { const sentinelPath = (0, import_path.join)( import_built.default.content.baseDir, ".intlayer", "cache", "intlayer-prepared.lock" ); await (0, import_chokidar.runOnce)( sentinelPath, async () => await (0, import_chokidar.prepareIntlayer)(import_built.default) ); } } ]; if (optimize) { plugins.push((0, import_intlayerPrunePlugin.IntlayerPrunePlugin)(import_built.default)); } return plugins; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { intlayerPlugin }); //# sourceMappingURL=intlayerPlugin.cjs.map