Skip to content

Commit

Permalink
Merge pull request #9 from perfectsense/feature/systemjs
Browse files Browse the repository at this point in the history
Replace requirejs with system.js for es6 builds in brightspot base and other future projects
  • Loading branch information
Tom Hoppe committed Jul 22, 2015
2 parents 8ca140e + 7c7fb20 commit 3db5f71
Show file tree
Hide file tree
Showing 7 changed files with 64,885 additions and 52 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Introduction

NOTE: Starting with version 2.0.0, bsp-grunt compiles [ECMAScript 6 modules](http://www.2ality.com/2014/09/es6-modules-final.html) instead of a [RequireJS modules](http://requirejs.org/). Work in 1.x.x if you need RequireJS.

Standard set of Grunt configuration for Brightspot projects using the following:

- [Autoprefixer](https://github.com/ai/autoprefixer)
- [Brightspot](http://www.brightspotcms.com/)
- [Grunt](http://gruntjs.com/)
- [LESS](http://lesscss.org/)
- [RequireJS](http://requirejs.org/)
- [r.js](http://requirejs.org/docs/optimization.html)
- [SystemJS Builder](https://github.com/systemjs/builder)

# Usage

Expand Down
66 changes: 24 additions & 42 deletions bsp-grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module.exports = function(grunt, config) {
var EXTEND = require('extend');
var _ = require('lodash');
var PATH = require('path');
var Builder = require('systemjs-builder');
var builder = new Builder();

grunt.initConfig(EXTEND(true, { }, {
bsp: {
Expand All @@ -28,6 +30,13 @@ module.exports = function(grunt, config) {
srcDir: '<%= bsp.maven.srcDir %>/<%= bsp.scripts.dir %>',
devDir: '<%= bsp.maven.destDir %>/<%= bsp.scripts.dir %>',
minDir: '<%= bsp.scripts.devDir %>.min'
},

systemjs: {
configOverrides: {},
srcFile: '<%= bsp.scripts.devDir %>/main.js',
destFile: '<%= bsp.scripts.minDir %>/main.min.js',
configFile: '<%= bsp.scripts.devDir %>/config.js'
}
},

Expand All @@ -37,11 +46,6 @@ module.exports = function(grunt, config) {
},

copy: {
requirejs: {
files: {
'<%= bsp.scripts.devDir %>/require.js': 'node_modules/requirejs/require.js'
}
},

bower: {
files: [ ]
Expand Down Expand Up @@ -105,7 +109,7 @@ module.exports = function(grunt, config) {
files: {
'<%= bsp.scripts.devDir %>/less.js':
'node_modules/grunt-contrib-less/node_modules/less/' +
grunt.file.readJSON('node_modules/grunt-contrib-less/node_modules/less/bower.json')['main']
grunt.file.readJSON('node_modules/grunt-contrib-less/node_modules/less/bower.json').main
}
}
},
Expand Down Expand Up @@ -136,23 +140,23 @@ module.exports = function(grunt, config) {
}
},

requirejs: {
dynamic: {
options: {
baseUrl: '<%= bsp.scripts.devDir %>',
dir: '<%= bsp.scripts.minDir %>',
modules: '<%= bsp.scripts.rjsModules %>',
optimize: 'uglify2'
}
}
},


watch: {
less: {
files: '<%= bsp.styles.srcDir %>' + '/**/*.less',
tasks: ['bsp-config-dest', 'copy:styles', 'less:compile', 'copy:compiledCSSForWatcher']
}
},

systemjs: {
dist: {
options: {
configFile: '<%= bsp.systemjs.configFile %>',
configOverrides: grunt.config('bsp.systemjs.configOverrides')
},
files: [
{ '<%= bsp.systemjs.destFile %>': '<%= bsp.systemjs.srcFile %>' }
]
}
}

}, (config || { })));
Expand All @@ -161,7 +165,7 @@ module.exports = function(grunt, config) {
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadTasks(__dirname + '/tasks');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.task.registerTask('bsp-config-dest', 'Configure build destination.', function() {
Expand All @@ -182,26 +186,6 @@ module.exports = function(grunt, config) {
grunt.log.writeln('Build destination: ' + grunt.config('bsp.maven.destDir'));
});

grunt.task.registerTask('bsp-config-requirejs', 'Configure RequireJS.', function() {
if (!grunt.config('requirejs.dynamic.options.mainConfigFile')) {
var config = grunt.config('bsp.scripts.rjsConfig');

if (!config) {
var firstModule = (grunt.config('requirejs.dynamic.options.modules') || [ ])[0];

if (firstModule) {
config = firstModule.name + '.js';
}
}

if (config) {
grunt.config('requirejs.dynamic.options.mainConfigFile', '<%= bsp.scripts.srcDir %>/' + config);
}
}

grunt.log.writeln('RequireJS main config: ' + grunt.config('requirejs.dynamic.options.mainConfigFile'));
});

grunt.task.registerTask('bower-prune', 'Prune extraneous Bower packages.', function() {
var done = this.async();

Expand Down Expand Up @@ -286,16 +270,14 @@ module.exports = function(grunt, config) {
grunt.registerTask('bsp', [
'bsp-config-dest', // configure the destination that maven creates
'clean:sourceCSS', // clean up the source directories of any compiled CSS that were copied there by a watcher
'bsp-config-requirejs',
'bower-prune',
'bower-install-simple:all',
'bower-configure-copy',
'copy:requirejs',
'copy:bower',
'copy:styles',
'less:compile',
'copy:scripts',
'requirejs:dynamic',
'systemjs',
'copy:less', // this copies less.js to allow for client side compilation
'copy:compiledCSS' // copies the compiled CSS to the target dir, this was the task performed by the autoprefixed before we removed it
]);
Expand Down
Loading

0 comments on commit 3db5f71

Please sign in to comment.