gruntjs - Yeoman webapp grunt file modification -
i try used yeoman webapp generator compass next project. in app folder structure follows.
app |-scripts |-styles |---global |-----components |---layout |---pages |---themes
so want build exact same structure after executing grunt build command. no need concatenate of minify css , js file. modified grundfile is:
// generated on 2015-06-19 using // generator-webapp 0.5.1 'use strict'; // # globbing // performance reasons we're matching 1 level down: // 'test/spec/{,*/}*.js' // if want recursively match subfolders, use: // 'test/spec/**/*.js' module.exports = function (grunt) { // time how long tasks take. can when optimizing build times require('time-grunt')(grunt); // load grunt tasks automatically require('load-grunt-tasks')(grunt); // configurable paths var config = { app: 'app', dist: 'dist' }; // define configuration tasks grunt.initconfig({ // project settings config: config, // watches files changes , runs tasks based on changed files watch: { bower: { files: ['bower.json'], tasks: ['wiredep'] }, js: { files: ['<%= config.app %>/scripts/{,*/}*.js'], tasks: ['jshint'], options: { livereload: true } }, jstest: { files: ['test/spec/{,*/}*.js'], tasks: ['test:watch'] }, gruntfile: { files: ['gruntfile.js'] }, compass: { files: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], tasks: ['compass:server'] }, styles: { files: ['<%= config.app %>/styles/{,*/}*.css'], tasks: ['newer:copy:styles'] }, livereload: { options: { livereload: '<%= connect.options.livereload %>' }, files: [ '<%= config.app %>/{,*/}*.html', '.tmp/styles/{,*/}*.css', '<%= config.app %>/images/{,*/}*' ] } }, // actual grunt server settings connect: { options: { port: 9000, open: true, livereload: 35729, // change '0.0.0.0' access server outside hostname: 'localhost' }, livereload: { options: { middleware: function (connect) { return [ connect.static('.tmp'), connect().use('/plugins', connect.static('./plugins')), connect.static(config.app) ]; } } }, test: { options: { open: false, port: 9001, middleware: function (connect) { return [ connect.static('.tmp'), connect.static('test'), connect().use('/plugins', connect.static('./plugins')), connect.static(config.app) ]; } } }, dist: { options: { base: '<%= config.dist %>', livereload: false } } }, // empties folders start fresh clean: { dist: { files: [{ dot: true, src: [ '.tmp', '<%= config.dist %>/*', '!<%= config.dist %>/.git*' ] }] }, server: '.tmp' }, // make sure code styles par , there no obvious mistakes jshint: { options: { jshintrc: '.jshintrc', reporter: require('jshint-stylish') }, all: [ 'gruntfile.js', '<%= config.app %>/scripts/{,*/}*.js', '!<%= config.app %>/scripts/vendor/*', 'test/spec/{,*/}*.js' ] }, // mocha testing framework configuration options mocha: { all: { options: { run: true, urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html'] } } }, // compiles sass css , generates necessary files if requested compass: { options: { sassdir: '<%= config.app %>/styles', cssdir: '.tmp/styles', imagesdir: '<%= config.app %>/images', javascriptsdir: '<%= config.app %>/scripts', fontsdir: '<%= config.app %>/styles/fonts', generatedimagesdir: '.tmp/images/generated', importpath: 'plugins', httpimagespath: '../images', httpgeneratedimagespath: '../images/generated', httpfontspath: 'fonts', relativeassets: false, assetcachebuster: false }, dist: { options: { generatedimagesdir: '<%= config.dist %>/images/generated' } }, server: { options: { debuginfo: true } } }, // add vendor prefixed styles //autoprefixer: { //options: { //browsers: ['> 1%', 'last 2 versions', 'firefox esr', 'opera 12.1'] //}, //dist: { // files: [{ //expand: true, //cwd: '.tmp/styles/', //src: '{,*/}*.css', //dest: '.tmp/styles/' //}] //} //}, // automatically inject bower components html file wiredep: { app: { ignorepath: /^\/|\.\.\//, src: ['<%= config.app %>/index.html'], exclude: ['plugins/bootstrap-sass-official/assets/javascripts/bootstrap.js'] }, sass: { src: ['<%= config.app %>/styles/{,*/}*.{scss,sass}'], ignorepath: /(\.\.\/){1,2}plugins\// } }, // renames files browser caching purposes rev: { dist: { files: { src: [ '<%= config.dist %>/scripts/{,*/}*.js', '<%= config.dist %>/styles/{,*/}*.css', '<%= config.dist %>/images/{,*/}*.*', '<%= config.dist %>/styles/fonts/{,*/}*.*', '<%= config.dist %>/*.{ico,png}' ] } } }, // reads html usemin blocks enable smart builds automatically // concat, minify , revision files. creates configurations in memory // additional tasks can operate on them useminprepare: { options: { dest: '<%= config.dist %>' }, html: '<%= config.app %>/index.html' }, // performs rewrites based on rev , useminprepare configuration usemin: { options: { assetsdirs: [ '<%= config.dist %>', '<%= config.dist %>/images', '<%= config.dist %>/styles' ] }, html: ['<%= config.dist %>/{,*/}*.html'], css: ['<%= config.dist %>/styles/{,*/}*.css'] }, // following *-min tasks produce minified files in dist folder imagemin: { dist: { files: [{ expand: true, cwd: '<%= config.app %>/images', src: '{,*/}*.{gif,jpeg,jpg,png}', dest: '<%= config.dist %>/images' }] } }, svgmin: { dist: { files: [{ expand: true, cwd: '<%= config.app %>/images', src: '{,*/}*.svg', dest: '<%= config.dist %>/images' }] } }, htmlmin: { dist: { options: { collapsebooleanattributes: true, collapsewhitespace: true, conservativecollapse: true, removeattributequotes: true, removecommentsfromcdata: true, removeemptyattributes: true, removeoptionaltags: true, removeredundantattributes: true, useshortdoctype: true }, files: [{ expand: true, cwd: '<%= config.dist %>', src: '{,*/}*.html', dest: '<%= config.dist %>' }] } }, // default, `index.html`'s <!-- usemin block --> take care // of minification. these next options pre-configured if not // wish use usemin blocks. // cssmin: { // dist: { // files: { // '<%= config.dist %>/styles/main.css': [ // '.tmp/styles/{,*/}*.css', // '<%= config.app %>/styles/{,*/}*.css' // ] // } // } // }, // uglify: { // dist: { // files: { // '<%= config.dist %>/scripts/scripts.js': [ // '<%= config.dist %>/scripts/scripts.js' // ] // } // } // }, // concat: { // dist: {} // }, // copies remaining files places other tasks can use copy: { dist: { files: [{ expand: true, dot: true, cwd: '<%= config.app %>', dest: '<%= config.dist %>', src: [ '*.{ico,png,txt}', 'images/{,*/}*.webp', '{,*/}*.html', 'styles/fonts/{,*/}*.*' ] }, { src: 'node_modules/apache-server-configs/dist/.htaccess', dest: '<%= config.dist %>/.htaccess' }, { expand: true, dot: true, cwd: '.', src: 'plugins/bootstrap-sass-official/assets/fonts/bootstrap/*', dest: '<%= config.dist %>' }, { //for font-awesome expand: true, dot: true, //cwd: 'plugins/font-awesome', cwd: '.', //src: ['fonts/*.*'], src: 'plugins/fontawesome/fonts/*', dest: '<%= config.dist %>' }, { //for font-awesome expand: true, dot: true, //cwd: 'plugins/font-awesome', cwd: '.', //src: ['fonts/*.*'], src: 'plugins/slick.js/fonts/*', dest: '<%= config.dist %>' }] }, styles: { expand: true, dot: true, cwd: '<%= config.app %>/styles', dest: '.tmp/styles/', src: '{,*/}*.css' } }, // generates custom modernizr build includes tests // reference in app modernizr: { dist: { devfile: 'plugins/modernizr/modernizr.js', outputfile: '<%= config.dist %>/scripts/vendor/modernizr.js', files: { src: [ '<%= config.dist %>/scripts/{,*/}*.js', '<%= config.dist %>/styles/{,*/}*.css', '!<%= config.dist %>/scripts/vendor/*' ] }, uglify: true } }, // run tasks in parallel speed build process concurrent: { server: [ 'compass:server', 'copy:styles' ], test: [ 'copy:styles' ], dist: [ 'compass', 'copy:styles', 'imagemin', 'svgmin' ] } }); grunt.registertask('serve', 'start server , preview app, --allow-remote remote access', function (target) { if (grunt.option('allow-remote')) { grunt.config.set('connect.options.hostname', '0.0.0.0'); } if (target === 'dist') { return grunt.task.run(['build', 'connect:dist:keepalive']); } grunt.task.run([ 'clean:server', 'wiredep', 'concurrent:server', //'autoprefixer', 'connect:livereload', 'watch' ]); }); grunt.registertask('server', function (target) { grunt.log.warn('the `server` task has been deprecated. use `grunt serve` start server.'); grunt.task.run([target ? ('serve:' + target) : 'serve']); }); grunt.registertask('test', function (target) { if (target !== 'watch') { grunt.task.run([ 'clean:server', 'concurrent:test', //'autoprefixer' ]); } grunt.task.run([ 'connect:test', 'mocha' ]); }); grunt.registertask('build', [ 'clean:dist', 'wiredep', 'useminprepare', 'concurrent:dist', //'autoprefixer', 'concat', 'cssmin', 'uglify', 'copy:dist', 'modernizr', 'rev', 'usemin' //'htmlmin' ]); grunt.registertask('default', [ 'newer:jshint', 'test', 'build' ]);
};
Comments
Post a Comment