Created
November 22, 2024 13:51
-
-
Save chrono-meter/e92920515b010d01bd5d32d2facf21d0 to your computer and use it in GitHub Desktop.
How to use `@wordpress/react-i18n`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Even though some module is not included in WordPress core, `wp-scripts` treats it as an external module. | |
| * | |
| * The following code will cause an error like: `Uncaught TypeError: Cannot read properties of undefined (reading 'I18nProvider')`. | |
| * ```js | |
| * import { I18nProvider } from '@wordpress/react-i18n'; | |
| * ``` | |
| */ | |
| const defaultConfig = require('@wordpress/scripts/config/webpack.config'); | |
| const DependencyExtractionWebpackPlugin = require('@wordpress/dependency-extraction-webpack-plugin'); | |
| const notWpCoreBundledModules = [ | |
| '@wordpress/react-i18n', | |
| ]; | |
| defaultConfig.plugins = [ | |
| ...defaultConfig.plugins.filter(plugin => plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'), | |
| new DependencyExtractionWebpackPlugin({ | |
| requestToExternalModule(request) { | |
| if (notWpCoreBundledModules.includes(request)) { | |
| return false; | |
| } | |
| // With `useDefaults: true`, `return;` means default behavior. | |
| }, | |
| requestToExternal(request) { | |
| if (notWpCoreBundledModules.includes(request)) { | |
| return false; | |
| } | |
| // With `useDefaults: true`, `return;` means default behavior. | |
| }, | |
| }), | |
| ]; | |
| module.exports = defaultConfig; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment