next-intlayer
Version:
Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.
114 lines • 4.08 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var withIntlayer_exports = {};
__export(withIntlayer_exports, {
withIntlayer: () => withIntlayer
});
module.exports = __toCommonJS(withIntlayer_exports);
var import_path = require("path");
var import_config = require("@intlayer/config");
var import_webpack = require("@intlayer/webpack");
var import_fs = require("fs");
const getNextVersion = () => {
try {
const nextConfigPath = import_config.ESMxCJSRequire.resolve("next/package.json");
const nextPkg = JSON.parse((0, import_fs.readFileSync)(nextConfigPath, "utf-8"));
return parseInt(nextPkg.version.split(".")[0], 10);
} catch (e) {
return void 0;
}
};
const nextMajorVersion = getNextVersion();
const isTurbopackEnabled = process.env.npm_lifecycle_script?.includes("--turbo");
const withIntlayer = (nextConfig = {}) => {
if (typeof nextConfig !== "object") {
nextConfig = {};
}
const intlayerConfig = (0, import_config.getConfiguration)();
const { mainDir, configDir, baseDir } = intlayerConfig.content;
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
const configurationPath = (0, import_path.join)(configDir, "configuration.json");
const relativeConfigurationPath = (0, import_path.relative)(baseDir, configurationPath);
const turboConfig = isTurbopackEnabled ? {
turbo: {
...nextConfig.experimental?.turbo ?? {},
resolveAlias: {
...nextConfig.experimental?.turbo?.resolveAlias ?? {},
"@intlayer/dictionaries-entry": relativeDictionariesPath,
"@intlayer/config/built": relativeConfigurationPath
},
rules: {
"*.node": {
as: "*.node",
loaders: ["node-loader"]
}
}
}
} : {};
const newConfig = {
// Only add `serverExternalPackages` if Next.js is v15+
...!nextMajorVersion || nextMajorVersion >= 15 ? {
serverExternalPackages: [
...nextConfig.serverExternalPackages ?? [],
"esbuild",
"module",
"fs",
"chokidar",
"fsevents"
]
} : {},
experimental: {
...nextConfig.experimental ?? {},
...turboConfig
},
webpack: (config, options) => {
if (typeof nextConfig.webpack === "function") {
config = nextConfig.webpack(config, options);
}
config.resolve.alias = {
...config.resolve.alias ?? {},
"@intlayer/dictionaries-entry": (0, import_path.resolve)(relativeDictionariesPath),
"@intlayer/config/built": (0, import_path.resolve)(relativeConfigurationPath)
};
config.externals.push({
esbuild: "esbuild",
module: "module",
fs: "fs",
chokidar: "chokidar",
fsevents: "fsevents"
});
config.module.rules.push({
test: /\.node$/,
loader: "node-loader"
});
const { isServer, nextRuntime } = options;
if (isServer && nextRuntime === "nodejs") {
config.plugins.push(new import_webpack.IntlayerPlugin());
}
return config;
}
};
return { ...nextConfig, ...newConfig };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
withIntlayer
});
//# sourceMappingURL=withIntlayer.cjs.map
;