-
Notifications
You must be signed in to change notification settings - Fork 31
Create React App v2 #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@rmccue @kadamwhite this is ready for review & testing etc now, you can clone and switch to this branch then in any WP set up you have run:
Then you can drop in this minimal <?php
/**
* Plugin Name: CRA WP test
*/
require_once 'react-wp-scripts.php';
add_action( 'wp_enqueue_scripts', function () {
ReactWPScripts\enqueue_assets( __DIR__, [
'handle' => 'react-wp',
] );
}, 200 );
add_action( 'wp_footer', function () {
echo '<div id="root"></div>';
} ); Then |
I followed the process above but ran into this error: when running |
@pdewouters classic, they updated a bunch of stuff and the default version constraint I had wasn't enough to avoid issues there! |
Just as a note, @roborourke We should make clear that this change will only work for WP 5.0+ because |
@roborourke Thank you for your work on this along with everyone else. When testing this the only issue I ran into was "reactpluginBuildURL is not defined" which prevented both After adding |
Hey thanks for testing!
Thanks for the bug report. Maybe I can add that to the webpack externals.
Unfortunately there’s a bunch more to do as they changed some files around
on a patch version recently. Will find some time to get it bang up to date
asap.
|
Thanks for this @roborourke! I've got it up and running locally no problem 🎉. So glad to be able to use things like SVG imports in React. Cheers! |
Opened a PR that upgrades to Create React App 3 as that's the latest version. Just a few minor updates required. https://github.com/humanmade/react-wp-scripts/pull/45/files |
Whoas. The JS world moves far too fast! I’ll check it out, thanks for the
PR :)
|
Just a heads up this might need tweaking again as the asset-manifest.json schema has changed in the latest CRA. |
@josephfusco thanks for the heads up. They have an interesting definition of semver over there... |
Fixed up the eslint no-undef warning by replacing the |
There's quite a lot in here, happy to refactor and move some things around but it all works and is in use on the Workflows plugin.
react
andreact-dom
are dependencies by defaultpublic/
directoryoutput.publicPath
is./
- ensures relative URLs usedoptimization.splitChunks.chunks
is set toasync
rather thanall
output.jsonpFunction
is set by sanitisingpackage.json
name fieldexternals
contains scripts provided by WP 5.x:wp
,React
,ReactDOM
,lodash
andmoment
publicPath.js
and an import for it which sets__webpack_public_path__
process.env.PUBLIC_URL
inserviceWorker.js
with known URL