Skip to content

Instantly share code, notes, and snippets.

@rileytg
Last active August 29, 2015 14:01
Show Gist options
  • Save rileytg/11543159 to your computer and use it in GitHub Desktop.
Save rileytg/11543159 to your computer and use it in GitHub Desktop.
require js config for a yeoman project
# grunt buildcontrol
npm install --save-dev grunt-build-control
# Require JS
npm install --save-dev grunt-processhtml grunt-contrib-requirejs
bower install --save requirejs
# Jasmine Testing
npm install --save-dev grunt-template-jasmine-requirejs grunt-contrib-jasmine
var require = {
paths: {
jquery: '../bower_components/jquery/dist/jquery',
requirejs: '../bower_components/requirejs/require'
},
shim: {}
}
// todo add shim example
{
buildcontrol: {
options: {
dir: 'dist',
commit: true,
push: true,
message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
},
pages: {
options: {
remote: 'https://github.com/fcflamingo/fcflamingo.git',
branch: 'gh-pages'
}
},
local: {
options: {
remote: '../',
branch: 'build'
}
}
},
processhtml: {
options: {
commentMarker: 'process'
},
dist: {
files: {
'<%= config.dist %>/index.html': '<%= config.dist %>/index.html'
}
}
},
requirejs: {
compile: {
options: {
almond: true,
baseUrl: '<%= config.app %>/scripts',
mainConfigFile: '<%= config.app %>/scripts/config.js',
name: 'main',
include: ['main', '../bower_components/requirejs/require'],
insertRequire: ['main'],
out: '<%= config.dist %>/scripts/optimized.js',
preserveLicenseComments: false,
wrap: true
}
}
},
jasmine: {
taskName: {
options: {
specs: 'spec/*Spec.js',
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: 'app/scripts/config.js',
requireConfig: {
baseUrl: 'app/scripts'
}
}
}
}
}
}
//// later on in the tasks config
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'cssmin',
'uglify',
'copy:dist',
'requirejs', // ****
'processhtml', // ****
'rev',
'usemin',
'htmlmin'
]);
// change the grunt.registerTask('test'... to match this:
grunt.registerTask('test', function (target) {
grunt.task.run([
'jasmine'
]);
});
<!-- process:js scripts/optimized.js -->
<script src="scripts/config.js" type="text/javascript"></script>
<script data-main="scripts/main" src="bower_components/requirejs/require.js"></script>
<!-- /process -->
require([], function() {
if(window.console) console.log("Welcome")
})
define([], function() {
return {}
})
define(['myModule'], function (myModule) {
describe('Give it some context', function () {
describe('maybe a bit more context here', function () {
it('should run here few assertions when x happens', function () {
// assertions
})
it('should run here few other assertions when y happens', function () {
// assertions
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment