2

I am going to import styles with CSS Module and make it work with server-side rendering. I tried the following methods but each one has its own caveat. What is the best possible way to require('.style.scss') if any side effects?

  1. Using the css-modules-require-hook:

    Advantage: Easy to configure. You just need to call the hook at the beginning of server code. You don't need to modify components.

    Caveat: It modifies the require.extensions global object, which is deprecated.

  2. Using the isomorphic-style-loader:

    Advantage: No more hooks to require.extensions.

    Caveat: Wrapping components with HOCs that uses the React Context, which is an experimental API and likely to break in future releases of React.

  3. Using the webpack-isomorphic-tools:

    Advantage: No dependency on require.extensions or Context (AFAIK).

    Caveat: Wrapping server inside webpack-isomorphic-tools instance. And can we please get rid of webpack-assets.json?

  4. Bundling server with Webpack:

    Advantage: No more hooks or injections.

    Caveat: In development, it is very cumbersome to bundle everything whenever the code changes and even makes it harder to debug in a large bundled .js file. Not sure - you may need to pass a bundled .js to test runner.

Disclaimer:

  • The advantages and caveats below are just my two cents, and actually I love all the libraries, plugins and approaches they took to solve the problem and really appreciate their efforts.
  • I am not a native English speaker, please correct me if I misrepresent myself.
1

1 Answer 1

0

In the end, I decided to hook the require.extensions in development. Probably it is not the best way, showing warning messages on console, like checksum mismatch, but in development mode, I can ignore it.

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

1 Comment

Can you explain what you mean about require.extensions??? I'm going through the same thing and am almost getting css-modules-require-hook working, but not sure if this is truly the right way to go.

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.