Skip to content

Instantly share code, notes, and snippets.

@skullbulb
Last active August 29, 2015 14:07
Show Gist options
  • Save skullbulb/a7c2ead6120c7dca152c to your computer and use it in GitHub Desktop.
Save skullbulb/a7c2ead6120c7dca152c to your computer and use it in GitHub Desktop.
Backbone.Marionette with Grunt and Browserify
var LayoutView = require('./views/LayoutView.js');
new LayoutView();
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
vendor: {
src: 'src/js/vendor.js',
dest: 'dist/js/vendor.js',
options: {
alias: [
'./node_modules/handlebars/runtime.js:handlebars',
'./node_modules/lodash/dist/lodash.underscore.js:underscore',
'jquery:',
'backbone:',
'backbone.marionette:'
]
}
},
application: {
src: 'src/js/application.js',
dest: 'dist/js/application.js',
options: {
browserifyOptions: {
debug: true
},
external: [
'handlebars', 'underscore', 'jquery', 'backbone', 'backbone.marionette'
]
}
}
},
watch: {
scripts: {
files: 'src/js/**/*.js',
tasks: ['browserify:application'],
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify');
grunt.registerTask('default', ['browserify:vendor', 'browserify:application', 'watch']);
};
var Marionette = require('backbone.marionette'),
_ = require('underscore'); // return lodash instance
module.exports = Marionette.LayoutView.extend({
initialize: function () {
console.log('Lodash version', _.VERSION);
}
});
{
"name": "sample",
"version": "1.0.0",
"description": "Your Application",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-browserify": "^3.0.1",
"grunt-contrib-watch": "^0.6.1"
},
"dependencies": {
"backbone": "^1.1.2",
"handlebars": "^2.0.0",
"jquery": "^2.1.1",
"lodash": "^2.4.1",
"backbone.marionette": "^2.2.1"
}
}
require('backbone').$ = require('jquery');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment