Importing CSS files in Isomorphic React Components

前端 未结 10 1288
失恋的感觉
失恋的感觉 2020-11-30 22:01

I have a React application with Components written in ES6 - transpiled via Babel and Webpack.

In some places I would like to include specific CSS files with specific

10条回答
  •  死守一世寂寞
    2020-11-30 22:42

    We had a similar problem with our isomorphic app (and a lot of other problems, you can find details here). As for the problem with CSS import, at first, we were using process.env.BROWSER. Later we've switched to babel-plugin-transform-require-ignore. It works perfectly with babel6.

    All you need is to have the following section in your .babelrc

    "env": {
       "node": {
         "plugins": [
           [
             "babel-plugin-transform-require-ignore", { "extensions": [".less", ".css"] }
           ]
         ]
       }
    }
    

    After that run your app with BABEL_ENV='node'. Like that:

    BABEL_ENV='node' node app.js.
    

    Here is an example of how a production config can look like.

提交回复
热议问题