devloco / create-react-wptheme

Create modern, React-enabled WordPress themes with a single command.
MIT License
359 stars 60 forks source link

Build ignoring user.prod.json homepage directory #45

Closed this-is-rafa closed 4 years ago

this-is-rafa commented 4 years ago

Running npm run build builds the theme but ignores the user.prod.json homepage directory.

After the script finishes, the output confirms it:

The project was built assuming it is hosted at /wordpress/wp-content/themes/theme/.
You can control this with the homepage field in your package.json.

This is running 3.4.0. I'm pretty sure it worked in a previous version.

devloco commented 4 years ago

Hey @this-is-rafa, Sorry about that. I'll get it fixed up this weekend.

Thanks for letting me know!

devloco commented 4 years ago

Just thinking... if you need a work-around for now, it might work to change the homepage value in package.json before running build, and then setting it back again if you need to go back into Dev Mode.

Annoying for sure, but if you need it sooner than I can fix it... that might work.

this-is-rafa commented 4 years ago

No worries, I knew about the workaround. Very much appreciate the project.

I spent a few hours digging through the code yesterday looking to see if I could see if I could find where it was happening, but I really don't understand the principles behind CRA. It definitely looks at the user.prod file to get the build directory, but it doesn't look like it uses the hompage attribute anywhere.

devloco commented 4 years ago

Wow, this is really difficult. I think I see why create-react-app doesn't use user modifiable config files. I need a couple of more days to iron this out... sorry about that.

Thanks

devloco commented 4 years ago

@this-is-rafa,

This should be all fixed up now.

Just FYI: One of the new features Facebook added to v3.4.0 is a way to do this via ENV vars. For example, I changed the build script line in my test theme's package.json file:

"build": "SET PUBLIC_URL=/wordpress8/wp-content/themes/bar2 && wptheme-scripts build",

Since that's built into create-react-app now, I decided it should take precedence. So if you have "homepage" in your user.prod.json set and you have ENV.PUBLIC_URL the ENV will win.

2020-04-13 18_16_20

Thanks again for reporting the bug!

this-is-rafa commented 4 years ago

Works great. Thanks again.

For others reading, my setup didn't require me to use the keyword 'SET'.