-
Notifications
You must be signed in to change notification settings - Fork 32
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
Question: Only for SPA? If used in a regular plugin, service-worker.js not loading. #28
Comments
Typically, I'd say you want to remove It is a good point though that we're taking all JS files and enqueuing them, whereas we really only want to load one entrypoint. Maybe we should have a entrypoint setting, defaulting to cc @kadamwhite who is on holiday, so expect a delay before any movement here :) (And let us know how the tutorial goes!) |
Hi @rmccue, cc @kadamwhite Thank you for the answer. Sorry for a late response. I also decided to go with deleting it. The tutorial is going great, just finished another part of it: https://www.ibenic.com/quiz-wordpress-rest-api-react-scripts-tool/ Also hosting a new webinar next Monday on integrating React WP Scripts: https://www.ibenic.com/webinar/ |
FWIW I had some success adding the following to my if ( process.env.NODE_ENV === 'production' ) {
// eslint-disable-next-line
__webpack_public_path__ = globalVarWithURLToBuildDirectory;
} The global var bit I added via Then in the const swUrl = `${globalVarWithURLToBuildDirectory}/service-worker.js`; Finally, I changed the npm build script in {
...,
"scripts": {
...,
"build": "NODE_ENV=production react-wp-scripts build"
}
} There are some issues with having multiple react apps / bundles and doing this though so I need to figure that out but this seemed to work. |
Actually a bit easier than that, along with the branch in #30 you can do the following:
package.json
config-overrides.js
Will document it on the wiki and close this issue out. |
I am using this tool for a tutorial of mine which I am writing.
It is a classic WordPress plugin which loads the React App as a part of a shortcode. Everything is working fine except trying to load the service-worker.js on the root URL.
I guess that is fine when it is used as a SPA.
If you plan for this tool to be used inside themes/plugins that are not intended for SPA sites, maybe there could be setting in $defaults: https://github.com/humanmade/react-wp-scripts/blob/master/loader.php#L130 to exclude service-worker.js from loading?
If not, just close it as if it was never asked :D
Thanks for such a nice tool!
The text was updated successfully, but these errors were encountered: