1

I'm trying to add a dynamic import() to my React component, and their working fine. Except for one huge detail: only the JavaScript is being loaded but the CSS, provided by CSS Modules, aren't.

Here's the code:

import React, { Component } from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";

class Routes extends Component {
  constructor(props) {
    super(props);

    this.state = {
      home: null
    };
  }

  componentDidMount() {
    import("../home/Home").then(Home => this.setState({ home: Home.default }));
  }

  render() {
    return (
      <Router>
        <div>
          <Route exact path="/" component={this.state.home} />
        </div>
      </Router>
    );
  }
}

This is what should happen:

enter image description here

This is what is happening:

enter image description here

React: 15.5.4 Webpack: 2.5.1

5
  • Do you want to post a repro repo to exemplify the issue? It's hard to work off of what you have posted. Commented May 15, 2017 at 17:50
  • What does importing the component and setting state in CDM accomplish that using a regular import does not? Commented May 15, 2017 at 17:55
  • @lux route code-splitting Commented May 15, 2017 at 17:58
  • @MatheusLima Cool, thanks Commented May 15, 2017 at 17:59
  • @JamesKraus I'll try to setup asap Commented May 15, 2017 at 17:59

1 Answer 1

2

Got it. I just had to pass allChunks: true to ExtractTextPlugin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.