UNPKG

react-scripts-intlayer

Version:

Integrate Intlayer with Create React App using custom React scripts for internationalization i18n and advanced Webpack configurations

104 lines 3.73 kB
"use strict"; 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 intlayerCracoPlugin_exports = {}; __export(intlayerCracoPlugin_exports, { intlayerCracoPlugin: () => intlayerCracoPlugin, overrideCracoConfig: () => overrideCracoConfig, overrideWebpackConfig: () => overrideWebpackConfig }); module.exports = __toCommonJS(intlayerCracoPlugin_exports); var import_config = require("@intlayer/config"); var import_webpack = require("@intlayer/webpack"); var import_path = require("path"); const intlayerConfig = (0, import_config.getConfiguration)(); const overrideWebpackConfig = ({ webpackConfig }) => { webpackConfig.externals = { ...typeof webpackConfig.externals === "object" ? webpackConfig.externals : {}, esbuild: "esbuild" // keep only esbuild external }; delete webpackConfig.externals.module; delete webpackConfig.externals.fs; delete webpackConfig.externals.path; delete webpackConfig.externals.vm; webpackConfig.module.rules.push({ test: /\.node$/, use: "node-loader" }); return webpackConfig; }; const overrideCracoConfig = ({ cracoConfig }) => { const { mainDir, baseDir, configDir } = 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); return { ...cracoConfig, webpack: { ...cracoConfig.webpack, plugins: { ...cracoConfig.webpack?.plugins, // Ensure we actually add IntlayerWebpackPlugin add: [ ...cracoConfig.webpack?.plugins?.add ?? [], new import_webpack.IntlayerPlugin() ] }, configure: { ...cracoConfig.webpack?.configure ?? {}, resolve: { ...cracoConfig.webpack?.configure?.resolve ?? {}, // 3) Provide browser fallbacks so these modules won’t error out in the browser. fallback: { ...cracoConfig.webpack?.configure?.resolve?.fallback ?? {}, process: import_config.ESMxCJSRequire.resolve("process/browser"), fs: false, module: false, path: false, vm: false } } }, // 4) Alias @intlayer/dictionaries-entry so it no longer tries to use the ESM that depends on `fs`, etc. alias: { ...cracoConfig.webpack?.alias, ...(0, import_config.getAlias)({ configuration: intlayerConfig, formatter: (value) => resolve(value) }) } } }; }; const intlayerCracoPlugin = { overrideCracoConfig, overrideWebpackConfig }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { intlayerCracoPlugin, overrideCracoConfig, overrideWebpackConfig }); //# sourceMappingURL=intlayerCracoPlugin.cjs.map