3

I am using laravel5.4 with vuejs2 to build a small project. I have just started learning vuejs2 with laravel. Using laravel-mix to compile my assets. In laravel-mix documentation i can't seem to find a way to add my own plain css file to be merged and watched.

I have my own css rules in public/css/custome.css file. what should i write in the webpack.mix.js file so that my this file is included and watched by laravel mix? Currently i have below lines in the file:

mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');

2 Answers 2

3

Move your custom CSS file into resources/css folder and write the configuration below in webpack.mix.js

Note: You probably won't have a css folder in resources, so just create one.

mix.styles([
'resources/css/custom.css'
], 'public/css')
Sign up to request clarification or add additional context in comments.

6 Comments

this does not work. i get error that mix.combine requires a full path to a filename as the last argument, whereas we are only providing a folder name (public/css).
Have a look at this, see if it helps? laravel.com/docs/5.5/mix#plain-css. And also, may I know what is the version of your laravel-mix package?
Hi Ru, i already tried this. What it does is tells the project to combine some plain css files into 1- say mycss.css,. However, my question was how do i tell the project to compile and add this mycss.css file into the central css file**(public/css/app.css)** that is watched by webpack so that i dont have to refer to this file explicitly in the header section of my application in a separate <link rel='stylesheet'> tab. I hope i was able to clarify my question?
btw, my version of mix: "laravel-mix": "^1.0"
Just note that if you want to do this you need to make sure the order your css files are "loaded/compiled" are in the correct order or your custom css will have no effect, especially e.g. if you are overwriting bootstrap styles.
|
2

I found a solution on Laracast and it worked for me.

Here are the steps :

  1. Save the content of public/css/custome.css in resources/assets/sass/_custome.scss

You have to change the file extension to .scss and add an underscore at the beginning. The underscore will be useful when importing in your main app.scss file.

  1. Import your resources/assets/sass/_custome.scss file into your resources/assets/sass/app.scss this way :

    /* importing _custome.scss from the same directory containing the following files 
       resources/assets/sass/{app.scss, _custome.scss, _variables.scss} */
    
    // import _custome.scss
    @import "custome";
    
    // import _variables.scss (custom variables for bootstrap-sass)
    @import "variables";
    
    // importing bootstrap-sass from node modules (if you are using bootstrap)
    @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
    
  2. Include this in your webpack.mix.js file

    mix.js('resources/assets/js/app.js', 'public/js')
    .sass('resources/assets/sass/app.scss', 'public/css');
    
  3. Compile with

    npm run dev
    

That's all.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.