-
Notifications
You must be signed in to change notification settings - Fork 38
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
Test code splitting with PostCSS #5
Comments
TL;DR CSS that is imported dynamically (i.e. via code-splitting) will wind up in I experimented this morning with code-splitting and CSS. The aim was to see how PostCSS / CSS extraction works with Javascript that has been imported dynamically, that in turn calls out to CSS code synchronously. I created a new ReactQL project, and used the following app code: app.js import React from 'react';
export default class Loader extends React.Component {
constructor() {
super();
this.state = {
codeSplit: <h1>Not loaded yet</h1>,
};
}
componentDidMount() {
import('./loaded').then(component => {
this.setState({
codeSplit: component.default(),
});
});
}
render() {
return (
<div>
<h1>From the loading component</h1>
{this.state.codeSplit}
</div>
);
}
} loaded.js import React from 'react';
import css from './loaded.css';
export default () => (
<h1 className={css.loaded}>This was code-split</h1>
); loaded.css .loaded {
color: red;
} I then built/ran the app with Since I'm making a call to import inside of Inside the So, conclusion: CSS that is loaded via 'dynamic' or code-split components will still wind up in our production CSS, even if it doesn't form part of the initial call. This means two things:
Just some food for thought, for now. I'll be investigating different loading patterns for CSS and will report back here/update the docs accordingly. |
I'll close this ticket. On reflection, having all stylesheet code wind up in a single file is ideal for the majority of use cases. It prevents flicker, and ensures that a consistent style is available across the whole application. If more dynamic CSS is required with code-split components, then there are plenty of libraries where CSS can be written as plain JS inside the component file, and loaded ad-hoc. Even basic React |
Per leebenson/reactql#4
The text was updated successfully, but these errors were encountered: