Skip to content

Commit

Permalink
all babel options transfering
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Jan 15, 2016
1 parent 09c17c1 commit 979c488
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
37 changes: 9 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var path = require('path');

module.exports = function(sails) {

return {
Expand All @@ -18,13 +19,7 @@ module.exports = function(sails) {
// Doesn't import polyfill by default
polyfill: false,
// Activates preset tranformations
presets: ['es2015'],
//can be false or a regex. Defaults to node_modules in babel
ignore: null,
//can be any regex. Only these files will be transpiled
only: null,
//an array of extensions, defaults to [".es6", ".es", ".jsx", ".js"] in babel
extensions: null
presets: ['es2015']
}
},

Expand All @@ -34,35 +29,21 @@ module.exports = function(sails) {
*/
configure: function() {

var config = sails.config[this.configKey];

// If the hook has been deactivated, just return
if (!sails.config[this.configKey].compile) {
if (!config.compile) {
sails.log.verbose("Babel hook deactivated.");
} else {

// Load babel
var options = {};

if (sails.config[this.configKey].polyfill) {
if (config.polyfill) {
require("babel-polyfill");
}

if (sails.config[this.configKey].presets && sails.config[this.configKey].presets.length > 0) {
options.presets = sails.config[this.configKey].presets;
}

if (sails.config[this.configKey].ignore !== null) {
options.ignore = sails.config[this.configKey].ignore;
}

if (sails.config[this.configKey].only) {
options.only = sails.config[this.configKey].only;
}

if (sails.config[this.configKey].extensions) {
options.extensions = sails.config[this.configKey].extensions;
}
delete config.polyfill;
delete config.compile;

require("babel-register")(options);
require("babel-register")(config);

sails.log.verbose("Babel hook activated. Enjoy ES6/7 power in your Sails app.");
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"dependencies": {
"babel-register": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"babel-polyfill": "^6.3.14"
"babel-polyfill": "^6.3.14",
"extend": "^3.0.0",
},
"devDependencies": {
"glob": "^5.0.3",
Expand Down

0 comments on commit 979c488

Please sign in to comment.