html - Using grunt for front end with php -
forgive me, i'm new grunt , don't typically code php. new project me. i'm trying use grunt, because it's awesome, html files have minimal php in them. installed regular grunt, not php grunt. realize maybe should have installed grunt-php. however, tried deleting gruntfile.js, installing grunt-php, , adding new configurations new gruntfile.js terminal keeps giving me "default" not found error, though default task there. know i'm doing wrong, don't know what. easier add php original grunt file? don't know how though. here's original file:
module.exports = function(grunt){ require("matchdep").filterdev("grunt-*").foreach(grunt.loadnpmtasks); grunt.initconfig({ htmlhint: { build: { options: { 'tag-pair': true, 'tagname-lowercase': true, 'attr-lowercase': true, 'attr-value-double-quotes': true, 'doctype-first': true, 'spec-char-escape': true, 'id-unique': true, 'head-script-disabled': true, 'style-disabled': true }, src: ['index.php'] } }, watch: { html: { files: ['index.php'], tasks: ['htmlhint'] }, js: { files: ['assets/js/**/*.js'], tasks: ['uglify'] }, css: { files: ['assets/sass/**/*.scss'], tasks: ['buildcss'] } }, sass: { build: { files: { 'build/css/master.css': 'assets/sass/master.scss' } } }, browsersync: { /*bsfiles: { src : ['assets/css/*.css', '*.html'], },*/ files: ['*.html', 'assets/templates/*.html'], options: { server: { basedir: "./" } } }, cssc: { build: { options: { consolidateviadeclarations: true, consolidateviaselectors: true, consolidatemediaqueries: true }, files: { 'build/css/master.css': 'build/css/master.css' } } }, cssmin: { build: { src: 'build/css/master.css', dest: 'build/css/master.css' } }, uglify: { build: { files: { 'build/js/base.min.js': ['bower_components/jquery/dis/jquery.min.js', 'bower_components/angular/angular.min.js', 'assets/js/**/*.js'] } } }, pkg: grunt.file.readjson('package.json'), phpunit:{ test:{ dir:'', options:{ bin: 'bin/phpunit', configuration:'app/phpunit.xml' } } }, 'sf2-cache-clear':{ options: {}, dev: {}, prod: {} } }); grunt.registertask('buildcss', ['sass', 'cssc', 'cssmin']); grunt.loadnpmtasks('grunt-contrib-sass'); grunt.loadnpmtasks('grunt-contrib-watch'); grunt.loadnpmtasks('grunt-browser-sync'); grunt.loadnpmtasks('grunt-phpunit'); grunt.loadnpmtasks('grunt-symfony2'); grunt.registertask('default', ['uglify', 'buildcss', 'browsersync','watch']); grunt.registertask('test', ['phpunit:test']); }; here grunt code tried adding grunt-php:
require('load-grunt-tasks')(grunt); grunt.initconfig({ php: { dist: { options: { hostname: '127.0.0.1', port: 9000, base: 'dist', // project root keepalive: false, open: false } } }, browsersync: { dist: { bsfiles: { src: [ // files want watch changes ] }, options: { proxy: '<%= php.dist.options.hostname %>:<%=php.dist.options.port %>', watchtask: true, notify: true, open: true, loglevel: 'silent', ghostmode: { clicks: true, scroll: true, links: true, forms: true } } } }, watch: { // watch tasks } }); grunt.registertask('serve', [ 'php:dist', // start php server 'browsersync:dist', // using php instance proxy 'watch' // other watch tasks want run ]); grunt.registertask('default', ['php']);
it way easier add grunt-php existing gruntfile. first install in project:
npm install grunt-php --save-dev then add task config in gruntfile (for example between pkg , php-unit):
php: { dist: { options: { base: 'build' } } }, and define task run server , default build + serve:
grunt.registertask('serve', [ 'php:dist', 'watch' ]); grunt.registertask('default', ['uglify', 'buildcss', 'serve', 'watch']);
Comments
Post a Comment