Ad

How To Compile Css In Production React Rails(5.2.3)

- 1 answer

I'm working on react with rails (5.2.3). I have imported css file in js. All styles are properly applied in the local (development) but in production, style does not seem to be applied. All touch functions are properly executed but only style is missing.

Which file should I modify to successfully apply style in the production?

import React from 'react'
import '/name_of_css.css'

class App extends React.Component {
..
}

and

javascript/packs/index.js

<Router>
  <Route path ="/" component = {App} />
</Router>

and then, views/controller_name/index.html, I imported js file like below.

<%= javascript_pack_tag 'index' %>

Again, I want to know how to apply css in the production for rails app! (:

Ad

Answer

Just add <%= stylesheet_pack_tag 'index' %> in your view.

From the Webpacker doc :

You can then link the JavaScript pack in Rails views using the javascript_pack_tag helper. If you have styles imported in your pack file, you can link them by using stylesheet_pack_tag

https://github.com/rails/webpacker#usage

Let me know if that solves your issue.

Ad
source: stackoverflow.com
Ad