Skip to content

Commit

Permalink
CommonJS builder config to Grunt style for easier handling and readab…
Browse files Browse the repository at this point in the history
…ility.
  • Loading branch information
RReverser committed Mar 11, 2014
1 parent 9e224e6 commit 25773ed
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
105 changes: 57 additions & 48 deletions grunt/config/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,67 +55,76 @@ function simpleBannerify(src) {
'\n' + src;
}

// Our basic config which we'll add to to make our other builds
function override(obj1, obj2) {
return _.merge({}, obj1, obj2, function (a, b) {
if (_.isArray(a)) {
return b;
}
})
}

var basic = {
entries: [
'./build/modules/React.js'
],
outfile: './build/react.js',
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: 'development'})],
after: [es3ify.transform, simpleBannerify]
src: './build/modules/React.js',
dest: './build/react.js',
options: {
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: 'development'})],
after: [es3ify.transform, simpleBannerify]
}
};

var min = _.merge({}, basic, {
outfile: './build/react.min.js',
debug: false,
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
var min = override(basic, {
dest: './build/react.min.js',
options: {
debug: false,
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
}
});

var transformer = {
entries:[
'./vendor/browser-transforms.js'
],
outfile: './build/JSXTransformer.js',
debug: false,
standalone: 'JSXTransformer',
transforms: [deamdify],
after: [es3ify.transform, simpleBannerify]
src: './vendor/browser-transforms.js',
dest: './build/JSXTransformer.js',
options: {
debug: false,
standalone: 'JSXTransformer',
transforms: [deamdify],
after: [es3ify.transform, simpleBannerify]
}
};

var addons = {
entries: [
'./build/modules/ReactWithAddons.js'
],
outfile: './build/react-with-addons.js',
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: 'development'})],
packageName: 'React (with addons)',
after: [es3ify.transform, simpleBannerify]
src: './build/modules/ReactWithAddons.js',
dest: './build/react-with-addons.js',
options: {
debug: false,
standalone: 'React',
transforms: [envify({NODE_ENV: 'development'})],
packageName: 'React (with addons)',
after: [es3ify.transform, simpleBannerify]
}
};

var addonsMin = _.merge({}, addons, {
outfile: './build/react-with-addons.min.js',
debug: false,
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
var addonsMin = override(addons, {
dest: './build/react-with-addons.min.js',
options: {
debug: false,
transforms: [envify({NODE_ENV: 'production'})],
after: [minify, bannerify]
}
});

var withCodeCoverageLogging = {
entries: [
'./build/modules/React.js'
],
outfile: './build/react.js',
debug: true,
standalone: 'React',
transforms: [
envify({NODE_ENV: 'development'}),
require('coverify')
]
};
var withCodeCoverageLogging = override(basic, {
options: {
debug: true,
transforms: [
envify({NODE_ENV: 'development'}),
require('coverify')
],
after: []
}
});

module.exports = {
basic: basic,
Expand Down
21 changes: 8 additions & 13 deletions grunt/tasks/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ var cjs = require('pure-cjs');
var grunt = require('grunt');

module.exports = function() {
var config = this.data;
var config = this.options({
transforms: [],
after: []
});

// This task is async...
var done = this.async();

// More/better assertions
// grunt.config.requires('outfile');
// grunt.config.requires('entries');
config.transforms = config.transforms || [];
config.after = config.after || [];
if (typeof config.after === 'function') {
config.after = [config.after];
}

// Extract options
var options = {
input: config.entries[0],
output: config.outfile,
input: this.files[0].src[0],
output: this.files[0].dest,
map: config.debug, // sourcemaps
exports: config.standalone, // global
transform: config.transforms,
Expand All @@ -30,8 +24,9 @@ module.exports = function() {

// Actually bundle it up
var _this = this;

cjs.transform(options).then(function(result) {
grunt.file.write(config.outfile, config.after.reduce(function(src, fn) {
grunt.file.write(_this.files[0].dest, config.after.reduce(function(src, fn) {
return fn.call(_this, src);
}, result.code));

Expand Down

0 comments on commit 25773ed

Please sign in to comment.