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

Feature: Watch mode without dev server #1427

Closed

Conversation

rschristian
Copy link
Member

@rschristian rschristian commented Sep 16, 2020

What kind of change does this PR introduce?

Feature

Did you add tests for your changes?

Yes. I added a test under watch.test.js that will run the file watcher and check to see if the built output is updated after a change occurs to the source. I figure this approach is simpler than the alternatives and still ensures the functionality works. So long as the built output changes the feature should be fine. I don't think we need a browser test.

Summary

This builds upon #1264 which leads back to & would close #1248.

Currently, the experience for developing SSR apps using the Preact CLI isn't great. To produce a bundle that can be used a developer needs to run the full production build and then rerun it on every change. This is slow and un-automated.

A solution, as pointed out by @oliverstr, is to provide an option to disable the dev server in watch mode. Any changes to the source would have the CLI rebuild and developers can consume the build in any way that they please.

@oliverstr's PR for implementing this feature (#1264) has been untouched since June 29th so I figure at this point it is fair to step in and try to complete. His PR had a few issues, besides being behind the current head, namely, it would not clear the build/ directory, leading to a large build up of temporary files, it ignored changes to src/* by default, and it could not handle CSS imports without wrapping them in a window check (if (typeof window !== "undefined") { ... }). I have fixed all three of these issues and a few more that popped up along the way to finish off his feature.

You can use the following repo to try this out, though you'll need to bring your own CLI copy with linking or relative paths. Simple server set up with Polka and Nodemon. Simply run yarn serve:dev in one terminal window and yarn serve in another. serve:dev starts the CLI watch mode, serve starts Polka with Nodemon. Nothing fancy.

ryanchristian4427/preact-cli-watch-without-devserver

Does this PR introduce a breaking change?

No breaking changes. This feature is behind a flag.

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2020

🦋 Changeset is good to go

Latest commit: 95e36a9

We got this.

This PR includes changesets to release 1 package
Name Type
preact-cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rschristian
Copy link
Member Author

A few changes are purely code-style based that my IDE caught. I figure I won't revert them for now as they do look to be correct changes, but I can undo this if it makes the PR too messy.

@rschristian rschristian marked this pull request as ready for review September 16, 2020 23:44
@rschristian rschristian requested a review from a team as a code owner September 16, 2020 23:44
@rschristian rschristian marked this pull request as draft September 16, 2020 23:54
@rschristian rschristian marked this pull request as ready for review September 17, 2020 20:38
@rschristian
Copy link
Member Author

I'd need to come back to look at this again.

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

Successfully merging this pull request may close these issues.

Watch mode without webpack's dev server
2 participants