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 Hot Loading #1255

Closed
manojVivek opened this issue Jun 26, 2024 Discussed in #1249 · 0 comments
Closed

CSS Hot Loading #1255

manojVivek opened this issue Jun 26, 2024 Discussed in #1249 · 0 comments
Labels
enhancement New feature or request

Comments

@manojVivek
Copy link
Collaborator

Discussed in #1249

Originally posted by Timoti June 17, 2024
Somewhere on the website I saw mention of "developer hot reloading"?
I would dearly dearly love to be able to have automatic reloading on save - especially css / js only reloads.
ATM, I've hacked something using Keyboard Maestro so I can reload while I'm in another app, but even this won't only reload CSS, which is what I really need.
If extensions could be installed, I'd install a CSS refresh extension, but obviously that's not an option either.

Is Hot reloading / css/js only reloading a thing? (sorry cant find wherever i saw the mention)

Can it be?

@manojVivek manojVivek added the enhancement New feature or request label Jun 26, 2024
minowau added a commit to minowau/responsively-app that referenced this issue Jul 14, 2024
solving issue responsively-org#1255

This project implements Hot Module Replacement (HMR) for a React-based Chrome extension, allowing developers to see real-time changes in their popup component without needing to refresh the entire extension. The following outlines the configuration and structure necessary for achieving this setup.

#### Key Components

1. **Webpack Configuration (`webpack.config.js`)**:
   - Configures Webpack for development and production modes, specifying the entry point and output settings.
   - Enables HMR in the development server for instant updates.

2. **Entry Point (`src/popup.js`)**:
   - Contains the main logic for the popup component, integrating the HMR logic to allow for module updates without a full reload.

3. **Index File (`src/index.js`)**:
   - Updated to support HMR with checks for `module.hot`, ensuring that the component re-renders on updates without refreshing the entire popup.

4. **Package Configuration (`package.json`)**:
   - Includes scripts for building and serving the application, specifying configurations needed for both development and production.

5. **Development Server**:
   - The command `npm start` launches a development server with HMR enabled, providing a smooth development experience.

#### Summary of Changes

- **HMR Logic**:
  - Added in `popup.js` using `if (module.hot) { ... }` to ensure updates are reflected in real-time.
  - Implemented in `index.js` to facilitate automatic re-rendering of the popup component on code changes.

- **Webpack Dev Server**: Configured with `hot: true` to support HMR functionality.

- **File Structure**: Organized files into a clear structure, facilitating maintainability and ease of access.

### Benefits

Implementing HMR improves the development workflow by reducing the time spent on refreshing and waiting for the extension to reload. This results in a more productive environment, allowing for faster iteration and debugging of features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants