SASS (Syntactically Awesome Stylesheets) is a CSS pre-processor that lets you use variables, mathematical operations, mixins, loops, functions, imports, and other interesting functionalities that make writing CSS much more powerful. In some ways, you may think of SASS as a style sheet extension language because it extends the standard CSS characteristics by introducing the benefits of a basic programming language. So SASS will compile your code and generate the CSS output a browser can understand.
Here is where an SCSS compiler comes into action.
Laravel Mix, a package developed by Laracasts creator Jeffrey Way, provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors. In other words, Mix makes it a cinch to compile and minify your application's CSS and JavaScript files.
If you don't have Node Js installed on your machine, you will need it.
Begin by installing Laravel Mix through NPM or Yarn.
mkdir my-app && cd my-app npm init -y npm install laravel-mix --save-dev
Next, create a Mix configuration file within the root of your new project.
touch webpack.mix.js
You should now have the following directory structure:
is your configuration layer on top of webpack.
Most of your time will be spent here.
Open webpack.mix.js and add the following code:
let mix = require("laravel-mix");
mix.sass("route-to-client-folder/themes/theme-name/styles/scss/main.scss", "route-to-client-folder/themes/theme-name/styles/css/")
We're now ready to bundle up our assets. Mix provides a command-line program called mix which triggers the appropriate webpack build. Give it a run now.
npx mix