项目作者: jovanovskajovana

项目描述 :
A Grunt build template with clean Sass architecture.
高级语言: JavaScript
项目地址: git://github.com/jovanovskajovana/sass-grunt-build-template.git


Sass plus Grunt build template

Here is a Grunt setup that will save you countless hours of trying to get the bundling up and running.



🚀 Quick Start

This quick start is intended to guide you through installing all the dependencies and understanding the basic file architecture.

Install the Grunt CLI

  1. npm install -g grunt-cli

Make sure you have a stable version of Node.js and install Grunt CLI globally on your machine.

Install Grunt

  1. npm install grunt --save-dev

Navigate to the project directory and add Grunt to the devDependencies list.

Setup the Gruntfile.js

  1. module.exports = function(grunt) {
  2. // Configure task(s)
  3. grunt.initConfig({
  4. pkg: grunt.file.readJSON('package.json'),
  5. uglify: {
  6. dev: {
  7. options: {
  8. //...
  9. },
  10. files: [{
  11. //...
  12. }]
  13. },
  14. build: {
  15. files: [{
  16. //...
  17. }]
  18. }
  19. },
  20. });
  21. // Load the plugins
  22. grunt.loadNpmTasks('grunt-contrib-uglify');
  23. // Register task(s)
  24. grunt.registerTask('default', ['uglify:dev']);
  25. grunt.registerTask('build', ['uglify:build']);
  26. };

First you need to configure all the tasks you will be using for automation, load the plugins, and then register the tasks for development or production. Keep the process simple by including only key tasks such as watch, sass, uglify, copy and connect.

Install Gruntplugins

  1. npm install grunt-contrib-watch --save-dev

Triggers the watch task to reload Gruntfile.js changes each time a watched file is modified.

  1. npm install node-sass grunt-sass --save-dev

Compiles Sass code to minified CSS files.

  1. npm install grunt-contrib-uglify --save-dev

Compresses JavaScript code into a target bundle.

  1. npm install grunt-contrib-copy --save-dev

Makes a copy of the static files in the production ready folder.

  1. npm install grunt-contrib-connect --save-dev

Runs a web server for local development.

🎨 Sass architecture

To keep stylesheets short, efficient and easier to maintain, build the interface as a collection of components. Split the code in separate folders such as base/, components/, layout/, pages/, and a single file at the root level, called main.scss, which imports them all to be compiled into a CSS stylesheet.

When working on smaller projects, you can keep all reusable partials into common/ folder and collect the page related styles into pages/.

  1. sass/
  2. |
  3. |– common/
  4. | |– _base.scss # Global html rules
  5. | |– _buttons.scss # Buttons
  6. | |– _footer.scss # Footer
  7. | |– _forms.scss # Form components
  8. | |– _header.scss # Header
  9. | |– _layout.scss # Basic layouts
  10. | |– _links.scss # Links
  11. | |– _margins.scss # Spacing helpers
  12. | |– _modal.scss # Modals
  13. | |– _tooltip.scss # Tooltip
  14. | |– _typography.scss # Typography rules
  15. | |– _variables.scss # Sass Variables
  16. |
  17. |– pages/
  18. | |– _contact.scss # Contact page specific styles
  19. | |– _home.scss # Home page specific styles
  20. | |– _news.scss # News page specific styles
  21. |
  22. |
  23. `– main.scss # Main Sass file


🎉 Start developing

The Gruntfile.js includes build and dev configuration. Build will compress JavaScript and CSS files into a production-ready directory, and dev is the default development mode.

  1. npm install

Clone this repository and install all dependencies.

  1. npm run dev

Continue local development and visit http://localhost:8000.

  1. npm run build

And, build all files for production.