Server Side CSS Modules Support

I am going to import styles with a CSS module and work with server-side rendering. I tried the following methods, but each has its own disclaimer. What is the best way require('.style.scss')if you have any side effects?

  • Using css-modules-require-hook :

    Advantage : easy to configure. You just need to call hook at the beginning of the server code. You do not need to change components.

    Caveat : It modifies a global object require.extensionsthat is deprecated .

  • Using isomorphic-style-loader :

    Advantage : no more bindings to require.extensions.

    Caution . Combining components using HOC using React Context, which is an experimental API and is likely to be broken in future React releases.

  • Using webpack-isomorphic-tools :

    Advantage : no dependency on require.extensionsor Context(AFAIK).

    Caution : wrapping the server inside an instance of a webpack-isomorphic tool. And can we get rid of webpack-assets.json ?

  • Combining the server with Webpack :

    Advantage : no more hooks or injections.

    . , , .js. - .js .

:

  • - , , , , .
  • , , , .
+2
1

, require.extensions . , , , , .

0

Source: https://habr.com/ru/post/1670327/


All Articles