Install react-app-rewired via yarn add react-app-rewired --dev
yarn add react-app-rewired --dev
{ … "scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build" } … }
module.exports = function override(config, env) { config.output.filename = 'widget.js'; config.optimization.splitChunks = { cacheGroups: { default: false, }, }; config.optimization.runtimeChunk = false; return config; };
import React from 'react'; import ReactDOM from 'react-dom'; import App from 'src/app/index'; //@ts-ignore window.myWidget = (containerElement, config) => { ReactDOM.render( <React.StrictMode> <App config={config} /> </React.StrictMode>, containerElement ); }; // this should be disabled if you don't want to mount the app automatically. // anyway this is very helpful while doing dev work if (document.getElementById("root") !== null) { //@ts-ignore window.myWidget( document.getElementById("root"), {} ); }
react — Apr 13, 2021