Skip to content

Commit

Permalink
Use Babel instead of JSXTransformer to compile examples in the browser (
Browse files Browse the repository at this point in the history
fix #16)
  • Loading branch information
sapegin committed Nov 10, 2015
1 parent 056b160 commit f4e18e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"prettyjson": "1.1.3",
"react-codemirror": "0.1.7",
"react-docgen": "2.3.1",
"react-tools": "0.13.3",
"react-transform-catch-errors": "1.0.0",
"react-transform-hmr": "1.0.1",
"redbox-react": "1.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/components/Preview/Preview.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.playgroundError {
margin: -1rem -1rem -1.2rem;
padding: 1rem;
line-height: 1.2;
font-size: .9rem;
color: #fff;
background: #c00;
}
25 changes: 11 additions & 14 deletions src/components/Preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import reactTools from 'react-tools';
import babel from 'babel-core/browser';
import Wrapper from 'components/Wrapper';

import s from './Preview.css';
Expand All @@ -29,29 +29,26 @@ export default class Preview extends Component {
}
}

compileCode() {
// TODO: Babel
return reactTools.transform(this.props.code, {
harmony: true
});
compileCode(code) {
return babel.transform(code, {stage: 0}).code;
}

executeCode() {
let mountNode = this.refs.mount;

try {
ReactDOM.unmountComponentAtNode(mountNode);
}
finally {
/* */
}
ReactDOM.unmountComponentAtNode(mountNode);

this.setState({
error: null
});

let { code } = this.props;
if (!code) {
return;
}

try {
let compiledCode = this.compileCode();
let compiledCode = this.compileCode(code);
let component = eval(compiledCode); /* eslint no-eval:0 */
let wrappedComponent = (
<Wrapper>
Expand All @@ -72,7 +69,7 @@ export default class Preview extends Component {
let { error } = this.state;
if (error) {
return (
<div className={s.playgroundError}>{error}</div>
<pre className={s.playgroundError}>{error}</pre>
);
}
else {
Expand Down
3 changes: 3 additions & 0 deletions src/make-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ module.exports = function(env) {
],
module: {
loaders: [
],
noParse: [
/babel-core\/browser.js/
]
},
postcss: function() {
Expand Down

0 comments on commit f4e18e1

Please sign in to comment.