From 33e42f3ede8b01f95868730c45b37bf601212c96 Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 09:48:37 +0100 Subject: [PATCH 1/6] added flag --es6 --- app/index.js | 2 ++ templates/common/_webpack.config.js | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 94ba957..3be315c 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') { diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index 8e41144..d9856e5 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -31,7 +31,6 @@ module.exports = { resolve: { extensions: ['', '.js', '.jsx'] }, - module: { preLoaders: [{ test: '\\.js$', From 188b523629286c7751d317e6a3fbb0dfb72ba72b Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 10:42:06 +0100 Subject: [PATCH 2/6] passing es6 option to template --- app/index.js | 4 +++- templates/common/_webpack.config.js | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/index.js b/app/index.js index 3be315c..a42f9d3 100644 --- a/app/index.js +++ b/app/index.js @@ -7,6 +7,7 @@ var generalUtils = require('../util.js'); var ReactWebpackGenerator = module.exports = function ReactWebpackGenerator(args, options, config) { yeoman.generators.Base.apply(this, arguments); this.option('es6'); + // this.es6 = this.options.es6; this.argument('appname', { type: String, required: false }); this.appname = this.appname || path.basename(process.cwd()); @@ -95,10 +96,11 @@ 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'); - this.template('../../templates/common/_webpack.config.js', 'webpack.config.js'); + this.template('../../templates/common/_webpack.config.js', 'webpack.config.js', this, {es6:true}); this.template('../../templates/common/_webpack.dist.config.js', 'webpack.dist.config.js'); this.copy('../../templates/common/Gruntfile.js', 'Gruntfile.js'); this.copy('../../templates/common/gitignore', '.gitignore'); diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index d9856e5..4657cba 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'); From c3f6abc95ecf36bada5777a6cdf9390c1d6b955a Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 10:45:45 +0100 Subject: [PATCH 3/6] adding 6to5 loader --- templates/common/_webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/common/_webpack.config.js b/templates/common/_webpack.config.js index 4657cba..93f550f 100644 --- a/templates/common/_webpack.config.js +++ b/templates/common/_webpack.config.js @@ -38,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' From 7421ef680f1a7dbfb14dbd989996d28a4ad2d743 Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 12:26:46 +0100 Subject: [PATCH 4/6] added 6to5 loader in webpack configs --- templates/common/_package.json | 4 +++- templates/common/_webpack.dist.config.js | 2 +- templates/common/karma.conf.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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.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' }] } }, From 505d7277e9f3c2206927c6b05c42e2ead94da9e4 Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 12:45:17 +0100 Subject: [PATCH 5/6] generating es6 modules if --es6 flag is used --- component/index.js | 7 +++++++ templates/javascript/Component.jsx | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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/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 %>; +<% } %> + From aeb2e370b4529c1518717cffbbd04e0595a8a830 Mon Sep 17 00:00:00 2001 From: Emil Stenberg Date: Wed, 10 Dec 2014 12:48:48 +0100 Subject: [PATCH 6/6] removed unused code --- app/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/index.js b/app/index.js index a42f9d3..198070e 100644 --- a/app/index.js +++ b/app/index.js @@ -7,7 +7,6 @@ var generalUtils = require('../util.js'); var ReactWebpackGenerator = module.exports = function ReactWebpackGenerator(args, options, config) { yeoman.generators.Base.apply(this, arguments); this.option('es6'); - // this.es6 = this.options.es6; this.argument('appname', { type: String, required: false }); this.appname = this.appname || path.basename(process.cwd()); @@ -100,7 +99,7 @@ ReactWebpackGenerator.prototype.packageFiles = function () { this.reactRouter = this.env.options.reactRouter; this.stylesLanguage = this.env.options.stylesLanguage; this.template('../../templates/common/_package.json', 'package.json'); - this.template('../../templates/common/_webpack.config.js', 'webpack.config.js', this, {es6:true}); + this.template('../../templates/common/_webpack.config.js', 'webpack.config.js'); this.template('../../templates/common/_webpack.dist.config.js', 'webpack.dist.config.js'); this.copy('../../templates/common/Gruntfile.js', 'Gruntfile.js'); this.copy('../../templates/common/gitignore', '.gitignore');