Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Created November 20, 2013 13:07
Show Gist options
  • Save Haraldson/7562873 to your computer and use it in GitHub Desktop.
Save Haraldson/7562873 to your computer and use it in GitHub Desktop.
grunt-contrib-require
Gruntfile.js
package.json
node_modules/
www/
assets/
js/
app/
app.js
lib/
main.js
module.exports = function(grunt)
{
grunt.initConfig(
{
pkg: grunt.file.readJSON('package.json'),
watch: {
css: {
files: ['www/assets/css/sass/**/*.scss'],
tasks: ['sass', 'autoprefixer', 'imageEmbed']
}
},
sass: {
dist: {
files: {
'www/assets/css/admin-interface.css': 'www/assets/css/sass/admin-interface.scss'
}
}
},
autoprefixer: {
dist: {
files: {
'www/assets/css/admin-interface.css': 'www/assets/css/admin-interface.css'
}
}
},
imageEmbed: {
dist: {
src: ['www/assets/css/admin-interface.css'],
dest: 'www/assets/css/admin-interface.css',
options: {
baseDir: 'www',
deleteAfterEncoding: false
}
}
},
requirejs: {
options: {
baseUrl: 'www/assets/js/lib/',
mainConfigFile: 'www/assets/js/main.js',
include: ['app'],
keepBuildDir: true
},
dev: {
options: {
out: 'www/assets/js/dev.js'
}
},
prod: {
options: {
out: 'www/assets/js/prod.js'
}
}
},
retire: {
files: ['www/assets/js/lib/*.js']
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-image-embed');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-retire');
grunt.registerTask('default', ['watch']);
grunt.registerTask('build', ['requirejs', 'retire', 'sass', 'autoprefixer', 'imageEmbed']);
};
// Stripped config file, removed a lot of shims and app specific paths
requirejs.config(
{
baseUrl: '/assets/js/lib/',
paths: {
'app': '../app[/...]', // Lots of lines like this...
'Handlebars': 'handlebars',
'domReady': 'require.domReady'
},
shim: {
'Handlebars': {
exports: 'Handlebars'
},
'hbs': {
deps: ['Handlebars', 'handlebars.helpers', 'i18nprecompile', 'json2'],
exports: 'Handlebars'
},
'json2': {
exports: 'JSON'
},
},
hbs: {
disableI18n: true
}
});
define(['app', 'domReady!'], function(App)
{
App.start();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment