Created
August 8, 2013 03:08
-
-
Save ymek/6181112 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* global module:false */ | |
| var lrSnippet = require('connect-livereload')(); | |
| var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; | |
| var rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest; | |
| var mountFolder = function (connect, dir) { | |
| return connect.static(require('path').resolve(dir)); | |
| }; | |
| module.exports = function(grunt) { | |
| // Load grunt tasks | |
| require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
| // Project configuration. | |
| grunt.initConfig({ | |
| //////////////////////////////////////////// | |
| // Metadata | |
| pkg: grunt.file.readJSON('package.json'), | |
| dirs: { | |
| dist: { | |
| base: 'dist', | |
| pub: '<%= dirs.dist.base %>/public', | |
| css: '<%= dirs.dist.pub %>/css', | |
| js: '<%= dirs.dist.pub %>/js' | |
| }, | |
| src: { | |
| base: 'sinatra', | |
| pub: '<%= dirs.src.base %>/public', | |
| css: '<%= dirs.src.pub %>/css', | |
| js: '<%= dirs.src.pub %>/js' | |
| } | |
| }, | |
| banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + | |
| '<%= grunt.template.today("yyyy-mm-dd") %>\n' + | |
| '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + | |
| '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + | |
| ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', | |
| //////////////////////////////////////////// | |
| watch: { | |
| options: { livereload: true }, | |
| dev: { | |
| files: ['<%= dirs.src.pub %>/**',] | |
| } | |
| }, | |
| connect: { | |
| rules: { | |
| '^/components/(.*)$': '/<%= dirs.src.pub %>/components/$1', | |
| '^/(.*)/(.*)$': '/sinatra/public/$1/$2', | |
| '^/.*$': '/sinatra/public/index.html' | |
| }, | |
| dev: { | |
| options: { | |
| port: 8181, | |
| hostname: '*', | |
| middleware: function(connect) { | |
| return [ | |
| proxySnippet, | |
| lrSnippet, | |
| rewriteRulesSnippet, | |
| mountFolder(connect, '.') | |
| ]; | |
| } | |
| }, | |
| /*proxies: [{ | |
| context: '/api', | |
| host: '127.0.0.1', | |
| port: 8080 | |
| }, | |
| { | |
| context: '/_ah', | |
| host: '127.0.0.1', | |
| port: 8080 | |
| }]*/ | |
| } | |
| }, | |
| clean: { | |
| dist: { | |
| files: [{ | |
| src: [ '<%= dirs.dist %>/*' ] | |
| }] | |
| } | |
| }, | |
| useminPrepare: { | |
| html: ['<%= dirs.src.pub %>/index.html'], | |
| options: { dest: '<%= dirs.dist.pub %>' } | |
| }, | |
| copy: { | |
| dist: { | |
| files: [{ | |
| expand: true, | |
| src: [ | |
| '<%= dirs.src %>/**', | |
| '!<%= dirs.src.js %>/**', | |
| '!<%= dirs.src.pub %>/components/**' | |
| ], | |
| dest: '<%= dirs.dist %>', | |
| filter: 'isFile' | |
| }] | |
| } | |
| }, | |
| concat: { | |
| options: { | |
| banner: '<%= banner %>', | |
| stripBanners: true | |
| }, | |
| }, | |
| ngmin: { | |
| dist: { | |
| expand: true, | |
| src: ['<%= dirs.dist.js %>/<%= pkg.name %>.js'] | |
| } | |
| }, | |
| uglify: { | |
| options: { | |
| mangle: false, | |
| banner: '<%= banner %>' | |
| }, | |
| /* | |
| * Example alternative to usemin automagicalness | |
| * | |
| dist: { | |
| files: { | |
| '<%= dirs.dist.js %>/<%= pkg.name %>.min.js': [ | |
| 'public/components/jquery/jquery.js', | |
| 'public/components/angular-latest/build/angular.js', | |
| 'public/components/angular-strap/dist/angular-strap.js', | |
| 'public/components/twitter/dist/js/bootstrap.js', | |
| '<%= ngmin.dist.src %>' | |
| ] | |
| } | |
| } | |
| */ | |
| }, | |
| rev: { | |
| dist: { | |
| files: { | |
| src: ['<%= dirs.dist.js %>/*.js', '<%= dirs.dist.css %>/*.css'] | |
| } | |
| } | |
| }, | |
| usemin: { | |
| html: ['<%= dirs.dist.pub %>/index.html'], | |
| options: { | |
| dirs: ['<%= dirs.dist.pub %>'], | |
| } | |
| }, | |
| karma: { | |
| options: { | |
| singleRun: true | |
| }, | |
| e2e: { | |
| configFile: 'karma-e2e.conf.js', | |
| browsers: ['PhantomJS'] | |
| } | |
| }, | |
| }); | |
| // Setup Tasks | |
| grunt.registerTask('build', [ | |
| //'karma:e2e', | |
| 'useminPrepare', | |
| 'copy', | |
| 'concat', | |
| 'ngmin', | |
| 'uglify', | |
| 'rev', | |
| 'usemin' | |
| ]); | |
| grunt.registerTask('devserver', [ | |
| 'configureProxies:dev', | |
| 'configureRewriteRules', | |
| 'connect:dev', | |
| 'watch:dev' | |
| ]); | |
| grunt.registerTask('default', [ | |
| 'clean:dist', | |
| 'build' | |
| ]); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment