Skip to content
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

CSS or JS doesn't seem to compile with yarn hot #3

Open
morrislaptop opened this issue Sep 9, 2019 · 5 comments
Open

CSS or JS doesn't seem to compile with yarn hot #3

morrislaptop opened this issue Sep 9, 2019 · 5 comments

Comments

@morrislaptop
Copy link

No description provided.

@jack-pallot
Copy link
Owner

I don't use HMR generally so I haven't noticed this. It's a bit more complicated to use with Laravel Mix on a non Laravel project, because Laravel provides a helper for linking directly to asset files using {{ mix('js/bundle.js') }}. Essentially, any changes made are stored on a different port, you should be able to browse to https://localhost:8080/dist/js/bundle.min.js and see changes sync on that url after running yarn hot.

Please could you confirm whether you're able to make template changes in hot mode? If so, I think I know what the issue is and can replicate the same environment, but it might take a while to get a solid solution working.

@morrislaptop
Copy link
Author

Yep I realised that changes are served through HTTP only and aren't put on the disk.

I might try and retrofit the logic from https://github.com/laravel/framework/blob/e04a7ffba8b80b934506783a7d0a161dd52eb2ef/src/Illuminate/Foundation/Mix.php#L10 into queue_theme_assets

Would you like a PR for this?

@jack-pallot
Copy link
Owner

Absolutely, if you want to give it a go then feel free, otherwise I don't mind taking a look. I think it could be simpler than the Laravel version though because we can make use of the default WP fallback if HMR isn't in use. I have done some testing and I think this is how it roughly works:

  • Check to see if a hot file exists in the directory (the file only exists when hot mode is running)
  • If the file exists then check to see if it's being served from http or https, and add the asset file path to the end of the localhost url
  • Check to see if the file path and URL have the appropriate forward slashes stripped
  • Return the localhost:8080 url with the asset file name if in hot mode
  • Otherwise return get_template_directory_uri() + the asset file name

I'm wondering if the get_file_contents part could also grab the URL out of the hot file, and check to see if a trailing forward slash exists at the end, then serve that URL. The Laravel version seems to hard code the localhost URL which may not work in some cases, I'm not sure. It might be easier just to hard core for the purposes of getting it working for now.

I think this could exist inside the required.php file as a get_mix_asset_path function or something. At some point the next version will have a different directory structure to allow for automatic updates, but we're not there yet. Placing the function here shouldn't cause issues migrating.

I'm going to keep the issue open while this is worked on if that's cool.

@jack-pallot jack-pallot reopened this Sep 10, 2019
@jack-pallot
Copy link
Owner

I've managed to get this working in the 0.3 dev branch.

If you want to test this out, you should be able to replace / add the following files from the dev branch:

functions/required.php
functions/get-mix-asset.php
package.json

It's worth mentioning that webpack will now generate an SSL certificate for the hot module URL, so you'll probably need to verify the certificate in your browser first to see any changes.

@morrislaptop
Copy link
Author

morrislaptop commented Sep 24, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants