This project was bootstrapped with Create React App and ejected to take full control over the Webpack configuration.
The workspace builds a single JS file that includes everything that is necessary to render a standalone component into an existing page.
To do so, the JS must be loaded by the browser, it will attach a coreMediaWidget
function
to the window
object, which can then be called to inject a standalone component into
the page.
To load the script you can
- Append it to the end of the HTML code and load it via the
<script>
tag - Use a browser plugin like Tampermonkey to inject the script on the client-side
Once the script is loadded, it can be used by calling
window.coreMediaWidget( <node> );
node
is either the ID of a DOM element, or the element itself.
Replace DOM node with ID standalone
with standalone component:
window.coreMediaWidget( 'standalone' );
Replace first DOM node with class 'cm-details' with standalone component:
window.coreMediaWidget( document.getElementsByClassName('cm-details')[0] );
<script src="main.js"></script>
<script>
window.coreMediaWidget(document.getElementById('poc-integration'));
</script>
Create a new script for the site that you want to inject the component to. Then load the JS from GitHub by requiring it and call the widget function.
The following example replaces the first hero element on the CoreMedia website with a standalone component.
// ==UserScript==
// @name CoreMedia Widget
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.coremedia.com/
// @grant none
// @require https://bgaworsk.github.io/in-store-poc-react/main.js
// ==/UserScript==
(function() {
'use strict';
let className = 'cm-details';
window.coreMediaWidget(document.getElementsByClassName(className)[0]);
})();
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#yarn-run-build-fails-to-minify
Copies bundled JS built by yarn run build
into demo HTML site at ./docs
.