Merge pull request #34 from me97esn/master

Support --es6 flag
This commit is contained in:
Simon Bailey 2014-12-10 12:30:55 +00:00
commit 80a19d1884
7 changed files with 21 additions and 7 deletions

View File

@ -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');

View File

@ -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',

View File

@ -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') { %>

View File

@ -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'

View File

@ -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'

View File

@ -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'
}]
}
},

View File

@ -19,5 +19,9 @@ var <%= classedName %> = React.createClass({
);
}
});
<% if (es6) { %>
export default <%= classedName %>;
<% } else { %>
module.exports = <%= classedName %>;
<% } %>