diff --git a/app/index.js b/app/index.js index 94ba957..198070e 100644 --- a/app/index.js +++ b/app/index.js @@ -6,12 +6,14 @@ var generalUtils = require('../util.js'); var ReactWebpackGenerator = module.exports = function ReactWebpackGenerator(args, options, config) { yeoman.generators.Base.apply(this, arguments); + this.option('es6'); this.argument('appname', { type: String, required: false }); this.appname = this.appname || path.basename(process.cwd()); this.appname = this._.camelize(this._.slugify(this._.humanize(this.appname))); this.scriptAppName = this._.capitalize(this.appname) + generalUtils.appName(this); + args = ['main']; if (typeof this.options.appPath === 'undefined') { @@ -93,6 +95,7 @@ ReactWebpackGenerator.prototype.createIndexHtml = function createIndexHtml() { }; ReactWebpackGenerator.prototype.packageFiles = function () { + this.es6 = this.options.es6; this.reactRouter = this.env.options.reactRouter; this.stylesLanguage = this.env.options.stylesLanguage; this.template('../../templates/common/_package.json', 'package.json'); diff --git a/component/index.js b/component/index.js index 5e37c8f..1d50772 100644 --- a/component/index.js +++ b/component/index.js @@ -3,12 +3,19 @@ var util = require('util'); var ScriptBase = require('../script-base.js'); var ComponentGenerator = module.exports = function ComponentGenerator(args, options, config) { + ScriptBase.apply(this, arguments); }; util.inherits(ComponentGenerator, ScriptBase); ComponentGenerator.prototype.createComponentFile = function createComponentFile() { + this.option('es6'); + + + this.es6 = this.options.es6; + console.log('es6:', this.es6) + this.generateSourceAndTest( 'Component', 'spec/Component', diff --git a/templates/common/_package.json b/templates/common/_package.json index d17a184..cf22820 100644 --- a/templates/common/_package.json +++ b/templates/common/_package.json @@ -34,7 +34,9 @@ "webpack-dev-server": "~1.6.5", "grunt-open": "~0.2.3", "jshint-loader": "~0.8.0", - "grunt-contrib-copy": "~0.5.0", + "grunt-contrib-copy": "~0.5.0",<% if (es6) { %> + "6to5": "^1.10.10", + "6to5-loader": "^0.2.3",<% } %> "grunt-contrib-clean": "~0.6.0",<% if (stylesLanguage === 'sass') { %> "sass-loader": "^0.2.0",<% } %><% if (stylesLanguage === 'less') { %> "less-loader": "^0.7.7",<% } %><% if (stylesLanguage === 'stylus') { %> diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index 8e41144..93f550f 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -4,7 +4,6 @@ * This file is set up for serving the webpak-dev-server, which will watch for changes and recompile as required if * the subfolder /webpack-dev-server/ is visited. Visiting the root will not automatically reload. */ - 'use strict'; var webpack = require('webpack'); @@ -31,7 +30,6 @@ module.exports = { resolve: { extensions: ['', '.js', '.jsx'] }, - module: { preLoaders: [{ test: '\\.js$', @@ -40,7 +38,7 @@ module.exports = { }], loaders: [{ test: /\.jsx$/, - loader: 'react-hot!jsx-loader?harmony' + loader: 'react-hot!<% if (es6) { %>6to5!<% }%>jsx-loader?harmony' },<% if (stylesLanguage === 'sass') { %> { test: /\.sass/, loader: 'style-loader!css-loader!sass-loader?outputStyle=expanded' diff --git a/templates/common/_webpack.dist.config.js b/templates/common/_webpack.dist.config.js index 9a27ac8..1bb78c7 100644 --- a/templates/common/_webpack.dist.config.js +++ b/templates/common/_webpack.dist.config.js @@ -45,7 +45,7 @@ module.exports = { loaders: [{ test: /\.jsx$/, - loader: 'jsx-loader?harmony' + loader: '<% if (es6) { %>6to5!<% }%>jsx-loader?harmony' }, { test: /\.css$/, loader: 'style-loader!css-loader' diff --git a/templates/common/karma.conf.js b/templates/common/karma.conf.js index 9ea3b86..abedc4c 100644 --- a/templates/common/karma.conf.js +++ b/templates/common/karma.conf.js @@ -28,7 +28,7 @@ module.exports = function (config) { loader: 'url-loader?limit=10000&mimetype=image/png' }, { test: /\.jsx$/, - loader: 'jsx-loader' + loader: '<% if (es6) { %>6to5!<% }%>jsx-loader' }] } }, diff --git a/templates/javascript/Component.jsx b/templates/javascript/Component.jsx index ae0869a..fe84508 100644 --- a/templates/javascript/Component.jsx +++ b/templates/javascript/Component.jsx @@ -19,5 +19,9 @@ var <%= classedName %> = React.createClass({ ); } }); - +<% if (es6) { %> +export default <%= classedName %>; +<% } else { %> module.exports = <%= classedName %>; +<% } %> +