javascript - electron ES6 code Unexpected token import -
development electron app.
use zhe es6 code in html success. write es6 code in alone js fail error.
package.json:
{ "name": "app", "version": "0.1.0", "main": "main.js", "dependencies": { "react": "^15.3.0", "react-dom": "^15.3.0" } }
index.html in electron success
<head> <meta charset="utf-8"> <title>stw</title> <script src="js/browser.min.js"></script> </head> <body> <div id="container"> </div> <script type="text/babel"> import react,{component} 'react'; import reactdom 'react-dom'; // import ff from'./foo.js'; class f1 extends component{ render(){ return <div>this react component</div> } }; reactdom.render(<f1/>,document.getelementbyid("container")) </script> </body> </html>
when use import ff from'./foo.js';
it's error , show "unexpected token import".
foo.js
import react 'react' export default class foo extends react.component{ render(){ return <div>this react component</div> } }
electron latest version.
es6 code in html <script type="text/babel">
success, how can use zhe es6 code in alone file ? =.=
as knowledge, support es6 modules first needs land in v8. have use:
const reactdom = require('react-dom')
Comments
Post a Comment