Skip to content

Instantly share code, notes, and snippets.

@iceberg53
Created August 31, 2018 08:40
Show Gist options
  • Save iceberg53/4b57b34a3aa987e3e7459a19aa51ac49 to your computer and use it in GitHub Desktop.
Save iceberg53/4b57b34a3aa987e3e7459a19aa51ac49 to your computer and use it in GitHub Desktop.
Steps for adding a custom css file to be compiled into the main css file (app.css) with laravel-mix and webpack.mix.js
  1. Save the content of public/css/custom.css in resources/assets/sass/_custom.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/_custom.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, _custom.scss, _variables.scss} */
    
    // import _custom.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
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment