Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !2131

Allow overriding the hotDevClient URL from a global var

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/roborourke/patch-1 into master May 11, 2017
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: roborourke

In multiple cases now I've wanted to use create-react-app but to build an app that's embedded in another context that won't work when served from localhost. The problem being that this script assumes window.location.hostname etc... will be the webpack dev server URL.

In my particular case when developing a WordPress theme using React or a WordPress plugin with an embedded react app for some fancy admin UI.

In WP I enqueue the build file from http://localhost:3000/build/js/main.js when in debug mode. I then used wp_localize_script() to then add this global variable eg:

wp_enqueue_script( 'react-app', 'http://localhost:3000/build/js/main.js' );
wp_localize_script( 'react-app', 'webpackHotDevClientURL', [
   'hostname' => 'localhost',
   'port' => 3000
] );

The project in question that this would benefit me on in particular is https://github.com/humanmade/Restsplain

I've searched around a lot and seems to come a fair bit on stackoverflow, this post almost got me there but patching it like this would be way more straightforward IMO.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/roborourke/patch-1