Created
June 12, 2014 01:42
-
-
Save joefiorini/775194693058031b4508 to your computer and use it in GitHub Desktop.
My setup for building an Angular.js app with Broccoli & 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
var ngMin = require('broccoli-ng-min'); | |
var uglify = require('broccoli-uglify-js'); | |
var compileSass = require('broccoli-ruby-sass'); | |
var pickFiles = require('broccoli-static-compiler'); | |
var mergeTrees = require('broccoli-merge-trees'); | |
var findBowerTrees = require('broccoli-bower'); | |
var env = require('broccoli-env').getEnv(); | |
var compileES6 = require('broccoli-es6-concatenator'); | |
var app = 'app/scripts'; | |
var dest = 'assets'; | |
app = pickFiles(app, { | |
srcDir: '/', | |
destDir: dest | |
}); | |
var styles = 'app/styles'; | |
styles = pickFiles(styles, { | |
srcDir: '/', | |
destDir: dest | |
}); | |
var vendor = 'bower_components'; | |
var sourceTrees = [app, styles, vendor]; | |
sourceTrees = sourceTrees.concat(findBowerTrees()); | |
var appAndDependencies = new mergeTrees(sourceTrees, { overwrite: true }); | |
var sourceMaps = pickFiles(appAndDependencies, { | |
srcDir: '/', | |
files: ['**/*.map'], | |
destDir: dest | |
}); | |
var appJs = compileES6(appAndDependencies, { | |
loaderFile: 'loader.js', | |
inputFiles: [ | |
dest + '**/*.js' | |
], | |
legacyFilesToAppend: [ | |
'angular/angular.js', | |
'angular-sanitize/angular-sanitize.js', | |
'angular-animate/angular-animate.js', | |
'jquery/dist/jquery.js' | |
], | |
wrapInEval: true, | |
outputFile: '/' + dest + '/scripts/application.js' | |
}); | |
var appCss = compileSass(sourceTrees, '/' + dest + '/main.scss', dest + '/styles/application.css', { | |
bundleExec: true, | |
'require': ['sass-css-importer', 'sass/half_pipe_functions'] | |
}); | |
if(env === 'public') { | |
appJs = uglify(appJs); | |
} | |
module.exports = mergeTrees([appJs, appCss, sourceMaps], {overwrite: true}); |
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
/*global module:false*/ | |
module.exports = function(grunt) { | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-connect-proxy'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-rails-server'); | |
grunt.loadNpmTasks('grunt-broccoli'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
grunt.loadNpmTasks('grunt-svgstore'); | |
var chain = require('connect-chain'); | |
var proxyM = require('grunt-connect-proxy/lib/utils'); | |
var proxy = proxyM.proxyRequest; | |
var fs = require('fs'); | |
var path = require('path'); | |
function assetServer(connect) { | |
var server = connect['static']('public'); | |
return function assetServer(request, response, next) { | |
var filePath = path.join('public', request.url); | |
if(request.url.match(/^\/assets/) && fs.existsSync(filePath)) { | |
server.apply(this, arguments); | |
} else { | |
next(); | |
} | |
}; | |
} | |
// Project configuration. | |
grunt.initConfig({ | |
// Metadata. | |
pkg: grunt.file.readJSON('package.json'), | |
dirs: grunt.file.readJSON('config/half-pipe.json'), | |
bowerOpts: grunt.file.readJSON('.bowerrc'), | |
jshint: { | |
options: { | |
jshintrc: '.jshintrc' | |
}, | |
gruntfile: { | |
src: 'Gruntfile.js' | |
} | |
}, | |
rails: { | |
options: { | |
port: 3001 | |
} | |
}, | |
broccoli: { | |
config: './Brocfile.js', | |
options: { | |
port: 3000, | |
host: '0.0.0.0', | |
config: './Brocfile.js', | |
proxy: 'http://0.0.0.0:3001' | |
}, | |
debug: { | |
options: { | |
dest: '<%= dirs.tmp %>' | |
} | |
}, | |
public: { | |
options: { | |
dest: '<%= dirs.tmp %>' | |
} | |
} | |
}, | |
proxies: [{ | |
context: '/', | |
host: 'localhost', | |
port: 3001, | |
https: false, | |
changeOrigin: false | |
}], | |
copy: { | |
finalize: { | |
files: [{ | |
expand: true, | |
cwd: '<%= dirs.tmp %>', | |
src: '**/*', | |
dest: 'public' | |
}] | |
} | |
}, | |
svgstore: { | |
options: { | |
svg: { | |
style: 'display:none' | |
} | |
}, | |
default: { | |
files: { | |
'public/assets/images/garment-icons.svg': ['app/icons/*.svg'] | |
} | |
} | |
} | |
}); | |
// Default task. | |
grunt.registerTask('default', 'build:debug'); | |
// Configure asset building pipeline | |
grunt.registerTask('build', ['build:debug']); | |
grunt.registerTask('build:debug', ['broccoli:debug:build', 'svgstore']); | |
grunt.registerTask('build:public', ['broccoli:public:build', 'svgstore', 'copy:finalize']); | |
// Configure preview server | |
grunt.registerTask('server', ['server:debug']); | |
grunt.registerTask('server:debug', ['build:debug', 'configureProxies', 'rails:server:start', 'broccoli:debug:serve']); | |
grunt.registerTask('server:public', ['build:public', 'broccoli:public:serve']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ngMin is not used explicitely in Brocfile. Is used implecitely or is broccoli-ng-min not used at all?