Last active
December 9, 2015 22:01
-
-
Save AS87-code/f68654320322e8bf4015 to your computer and use it in GitHub Desktop.
Grunt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create package.json | |
npm install | |
npm install -g grunt-cli | |
--- | |
npm install grunt-contrib-concat --save-dev //объеденение файлов | |
npm install grunt-contrib-uglify --save-dev //минификация кода | |
npm install grunt-contrib-imagemin --save-dev //оптимизация изображений | |
npm install grunt-contrib-sass --save-dev //scss to css | |
npm install grunt-contrib-compass --save-dev //compass | |
npm install grunt-postcss --save-dev | |
npm install grunt-postcss pixrem autoprefixer cssnano //fallback for rem, autoprefix, css mini | |
npm install grunt-csscomb --save-dev //css comb | |
npm install grunt-contrib-watch --save-dev //file watcher | |
npm install grunt-contrib-clean --save-dev //cleaning | |
npm install grunt-bower-concat --save-dev --> https://github.com/sapegin/grunt-bower-concat | |
bower_concat: { | |
all: { | |
dest: 'build/_bower.js', // Склеенный файл | |
exclude: [ // Пакеты, которые нужно исключить из сборки | |
'jquery', // Если jQuery подключается с CDN Гугла | |
'modernizr' // Если подключаем скрипты в конце страницы; Modernizr нужно подключать в <head> | |
] | |
} | |
}, | |
concat: { | |
main: { | |
src: [ | |
'build/_bower.js', | |
'scripts/*.js' // Скрипты вашего сайта | |
], | |
dest: 'build/scripts.js' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
// 1. Вся настройка находится здесь | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
/* concat: { | |
dist: { | |
src: [ | |
'js/libs/!*.js', // Все JS в папке libs | |
'js/app.js' // Конкретный файл | |
], | |
dest: 'js/build/production.js', | |
} | |
},*/ | |
uglify: { | |
build: { | |
src: 'js/common.js', | |
dest: 'js/common.min.js' | |
} | |
}, | |
imagemin: { | |
dynamic: { | |
files: [{ | |
expand: true, | |
cwd: 'media/img/', | |
src: ['**/*.{png,jpg,gif}'], | |
dest: 'media/img_min/' | |
}] | |
} | |
}, | |
compass: { | |
dist: { | |
options: { | |
config: 'config.rb' | |
} | |
} | |
}, | |
csscomb: { | |
dist: { | |
options: { | |
config: '.csscomb.json' | |
}, | |
files: { | |
'css/dev/_style.css': ['css/dev/style.css'], | |
'css/dev/_main_skin.css': ['css/dev/main_skin.css'], | |
'css/style.css': ['css/dev/style.css'], | |
'css/main_skin.css': ['css/dev/main_skin.css'] | |
} | |
} | |
}, | |
postcss: { | |
options: { | |
//map: true, // inline sourcemaps | |
// or | |
map: { | |
inline: false, // save all sourcemaps as separate files... | |
annotation: 'css/dev' // ...to the specified directory | |
}, | |
processors: [ | |
require('pixrem')(), // add fallbacks for rem units | |
require('autoprefixer')({browsers: 'last 2 versions'}), // add vendor prefixes | |
require('cssnano')() // minify the result | |
] | |
}, | |
dist: { | |
src: 'css/*.css' | |
} | |
}, | |
clean: { | |
build: ["css/dev/style.css", "css/dev/main_skin.css"] | |
}, | |
watch: { | |
options: { | |
dateFormat: function(time) { | |
grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString()); | |
grunt.log.writeln('Waiting for more changes...'); | |
}, | |
livereload: true | |
}, | |
scripts: { | |
files: ['js/*.js'], | |
tasks: ['uglify'], | |
options: { | |
spawn: false, | |
livereload: true | |
} | |
}, | |
scss: { | |
files: ['css/dev/scss/*.scss'], | |
tasks: ['compass', 'csscomb', 'postcss', 'clean'], | |
options: { | |
spawn: false | |
} | |
}, | |
html:{ | |
files: ['./**/*.html'], | |
tasks: [], | |
options: { | |
spawn: false, | |
livereload: true | |
} | |
}, | |
php:{ | |
files: ['./**/*.php'], | |
tasks: [], | |
options: { | |
spawn: false, | |
livereload: true | |
} | |
} | |
} | |
}); | |
// 3. Тут мы указываем Grunt, что хотим использовать этот плагин | |
//grunt.loadNpmTasks('grunt-contrib-concat'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-imagemin'); | |
grunt.loadNpmTasks('grunt-contrib-compass'); | |
grunt.loadNpmTasks('grunt-postcss'); | |
grunt.loadNpmTasks('grunt-csscomb'); | |
grunt.loadNpmTasks('grunt-contrib-clean'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
// 4. Указываем, какие задачи выполняются, когда мы вводим «grunt» в терминале | |
grunt.registerTask('default', ['uglify', 'imagemin', 'compass', 'csscomb', 'postcss', 'clean']); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "test-project", | |
"version": "0.1.0", | |
"devDependencies": { | |
"grunt": "~0.4.5", | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment