Skip to content

Add hot reloading #24

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

Merged
merged 6 commits into from
Jan 15, 2017
Merged

Add hot reloading #24

merged 6 commits into from
Jan 15, 2017

Conversation

clessg
Copy link
Contributor

@clessg clessg commented Dec 24, 2016

Hot reloading of CSS modules does not work out-of-the-box - module.hot.accept has to be used. Ideally, it's placed right by the component importing the CSS:

import React from 'react';
import './Button.css';

if (module.hot) {
  module.hot.accept('./Button.css', function () {
    require('./Button.css');
  });
}

export default function Button() {
  return <div styleName="root">Button</div>;
}

This is a pain to repeat for every single component. Fortunately, we can modify the AST to add it automatically.

@gajus
Copy link
Owner

gajus commented Jan 6, 2017

Thank you @clessg for the addition. I really like the suggestions. However, given that this is non-webpack specific package, this needs to be configurable.

Could you update the PR to make this behaviour configurable using webpackHotModuleReloading option?

@tyler-dot-earth
Copy link

tyler-dot-earth commented Jan 6, 2017

I did not have to add this to get hot reloading working in my own webpack 2 setup. Perhaps it's because I'm using react-hot-loader 3.0.0-beta.6? https://github.com/tsnieman/webpack2test/blob/master/package.json

@clessg
Copy link
Contributor Author

clessg commented Jan 6, 2017

@gajus Silly me. I forgot not everybody uses webpack yet. I'll update the PR asap.

@tsnieman Yeah, RHL 3 does, incidentally, cause CSS modules to be hot reloaded, though I'm not sure it's intentional. We could just tell people to use RHL, but it's been unstable for a long time, and is currently painful & time-consuming to set up. I've never successfully added RHL 3 to any of my projects - there's always bugs or unexpected behavior. props to you for trying (I make no apologies).

@gajus
Copy link
Owner

gajus commented Jan 15, 2017

🥇

@gajus
Copy link
Owner

gajus commented Jan 15, 2017

Please add a description of the configuration to https://github.com/gajus/babel-plugin-react-css-modules#configuration.

@clessg
Copy link
Contributor Author

clessg commented Jan 15, 2017

Ha, I literally just did that.

@clessg
Copy link
Contributor Author

clessg commented Jan 15, 2017

@gajus Before I head out, is there anything else that obviously needs fixed/changed?

@gajus
Copy link
Owner

gajus commented Jan 15, 2017

@gajus Before I head out, is there anything else that obviously needs fixed/changed?

Not on the surface of it. I am going to pull the branch and test it out.

@clessg
Copy link
Contributor Author

clessg commented Jan 15, 2017

Sounds good. 👍

@gajus gajus merged commit 00dc4b3 into gajus:master Jan 15, 2017
@gajus
Copy link
Owner

gajus commented Jan 15, 2017

Thank you @clessg !

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

Successfully merging this pull request may close these issues.

3 participants