UNPKG

react-scripts-intlayer

Version:

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

49 lines (47 loc) 1.72 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); let node_path = require("node:path"); let _intlayer_config_node = require("@intlayer/config/node"); let _intlayer_config_utils = require("@intlayer/config/utils"); let _intlayer_webpack = require("@intlayer/webpack"); let defu = require("defu"); //#region src/intlayerCracoPlugin.ts const intlayerConfig = (0, _intlayer_config_node.getConfiguration)(); const alias = (0, _intlayer_config_utils.getAlias)({ configuration: intlayerConfig, formatter: (value) => (0, node_path.join)(process.cwd(), value) }); /** * Override the final CRA Webpack config. * We explicitely type the return as WebpackConfig to solve TS2742. */ const overrideWebpackConfig = ({ webpackConfig }) => { if (typeof webpackConfig.externals === "object") webpackConfig.externals = { ...webpackConfig.externals, esbuild: "esbuild" }; webpackConfig.module?.rules?.push({ test: /\.node$/, use: "node-loader" }); return webpackConfig; }; /** * Override the CRACO config itself to set up aliases, fallbacks, and plugins. */ const overrideCracoConfig = ({ cracoConfig }) => (0, defu.defu)({ webpack: { plugins: { add: [...cracoConfig.webpack?.plugins?.add ?? [], new _intlayer_webpack.IntlayerPlugin(intlayerConfig)] }, alias } }, cracoConfig); /** * A CRACO plugin that adds the Intlayer configuration to the webpack configuration * and sets the environment variables. */ const intlayerCracoPlugin = { overrideCracoConfig, overrideWebpackConfig }; //#endregion exports.intlayerCracoPlugin = intlayerCracoPlugin; exports.overrideCracoConfig = overrideCracoConfig; exports.overrideWebpackConfig = overrideWebpackConfig; //# sourceMappingURL=intlayerCracoPlugin.cjs.map