0

I have some issues with using React in Laravel 5.5. Every time I add or make changes to a component, I have to run npm run dev to compile the thing. When I do this the contents of css/app.css get reset, so I cannot write styles to this file.

Styles get unchanged if I have them in another CSS file, but I'd like to have my main styles written in css/app.css.

How can I do this?

3
  • You are not supposed to add styles on css/app.css file. That file is generated everytime you compile your assets. Commented Oct 13, 2017 at 16:56
  • @Jackowski sorry for a stupid question then, but if it's autogenerated every time assets are compiled then why it is even present? Commented Oct 13, 2017 at 17:09
  • Everytime you run npm run dev your styling assets are aggregated in one single file (css/app.css). This way in your html files you just need to add this file to the head of your document and you'll have access to all your styles. Commented Oct 13, 2017 at 17:15

1 Answer 1

1

Keep all your css styles in a file in your resources directory and add the below code to end of your webpack.mix.js file.

mix.styles('path to your css file in resources directory', 'public/css/app.css');

If you are using sass use the below code

mix.sass('path to your css file in resources directory', 'public/css/app.css');

Also you no need to run npm run dev each time you make changes to your components. just run npm run watch and it will continuously look for changes and re-compile the components if anything is changed.

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.