Last active
March 28, 2018 16:57
-
-
Save painedpineapple/2bd08595ab3662c313eb6555d35bcedc to your computer and use it in GitHub Desktop.
This file contains 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
// index.js – don't let registerServiceWorker run in WP environment | |
if (process.env.NODE_ENV !== 'production') { | |
registerServiceWorker() | |
} | |
// functions.php | |
function install_react_app($app_dir = 'react-app') { | |
$directory = get_template_directory_uri() . '/' . $app_dir; | |
$manifest = json_decode(file_get_contents($directory . '/build/asset-manifest.json'), true); | |
if(isset($manifest['main.css'])) { | |
wp_enqueue_style( 'react-app-css', $directory . '/build/' . $manifest['main.css'] ); | |
} | |
echo isset($manifest['main.js']); | |
if(isset($manifest['main.js'])) { | |
wp_register_script( 'react-app-js', $directory . '/build/' . $manifest['main.js'], array(), false, true ); | |
wp_enqueue_script( 'react-app-js' ); | |
} | |
} | |
function my_scripts () { | |
install_react_app(); | |
} | |
add_action( 'wp_enqueue_scripts', 'my_scripts' ); | |
// template.php | |
<?php | |
/** | |
* Template Name: Template | |
*/ | |
get_header(); ?> | |
<div id="root"></div> | |
<?php get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment