问题
I am new to web development. I have read about SCSS/SASS and I realized it is not what the browser looks for, so it should be compiled to pure CSS. My question is did I get it right:
whenever I make a change to my SCSS file, I should then compile it and then see the result.
whenever I want to update my website, I should have a special script on my server side to translate the new SCSS files to pure CSS and that happens only once per update. (The number of CSS files is high and I wish to keep only the SCSS on my repository).
I would be thankful If you have any further information.
tnx a lot
回答1:
For compiling the SCSS to CSS, we use task runners such as Gulp, Webpack etc. I'll explain taking Gulp is an example.
What is Gulp?
Gulp is task runner used as a streaming build system in front-end web development process. Mainly used the automation of time-consuming and repetitive tasks involved in web development like minification, concatenation, compilation, unit testing, linting, optimization, etc.
You can use Gulp for compiling your SCSScode CSS and through gulp, you can also keep watch over the changes live.
To install Gulp you must have Node Js install in your system. After that use npm i gulp-cli -g to install gulp. You can find usage information on its official website.
To setup SCSS compilation to CSS, this is the best article you can find to getting started with Gulp for SCSS compilation and other tasks. Gulp for Beginners
回答2:
I will use Laravel as an example.
Laravel comes with Laravel Mix, which allows you to compile SCSS, LESS, etc into CSS by using Webpack internally. (it also does stuff with js)
Laravel comes with the folder resources/assets/sass by default, and this is where you put your scss/sass files.
It then compiles those files and puts them in your public/css folder whenever you run npm run dev. You can also use npm run watch to compile those files whenever you make changes and save the scss files.
It also has npm run prod command, which compiles the files in a minified format, which makes the files lighter.
If you're writing all your css with SCSS you don't even need to put the public/css folder in your git repository.
Whenever you push changes to git and want to update them in the server, just update the server's repository and run the compiling command that you have.
If you're not using git to push changes to the server, you can just compile the CSS files using npm run prod and push these files to the server via FTP or whichever way you're doing it.
来源:https://stackoverflow.com/questions/52165157/when-to-compile-sass