[英]ES6 Module loading with Webpack and Babel Issue
My compiled jsx module scripts are not compiling for some reason. 由于某些原因,我的已编译jsx模块脚本未编译。
Here is the directory structure 这是目录结构
Here are my 2 jsx files 这是我的2个jsx文件
import React from 'react'; import ReactDOM from 'react-dom'; import helloWorldDisplay from './helloWorldDisplay.jsx'; var helloWorldBox = React.createClass({ render : function(){ return ( <div> <helloWorldDisplay/> </div> ); } }); ReactDOM.render(<helloWorldBox/>, document.getElementById('output'));
import React from 'react'; var helloWorldDisplay = React.createClass({ render : function(){ return ( <div> Hello World </div> ); } });
import helloWorldBox from './helloWorldComponent/helloWorldBox.jsx'; import helloWorldDisplay from './helloWorldComponent/helloWorldDisplay.jsx';
When my bundle.js gets created by webpack it looks like this 当我的bundle.js由webpack创建时,它看起来像这样
/************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports) { import helloWorldBox from './helloWorldComponent/helloWorldBox.jsx'; import helloWorldDisplay from './helloWorldComponent/helloWorldDisplay.jsx'; /***/ } /******/ ]);
Here is the webpack.config.js file 这是webpack.config.js文件
var path = require('path'); var webpack = require('webpack'); module.exports = { entry: './scripts/main.js', output: { path: __dirname + '/dist', filename: 'bundle.js' }, module: { loaders: [ { test: /\\.jsx$/, loader: 'babel-loader', exclude: /(node_modules|bower_components)/, query: { presets: ['es2015', 'react'] } } ] }, };
import React from 'react';
var helloWorldDisplay = React.createClass({
render : function(){
return (
<div>
Hello World
</div>
);
}
});
export default helloWorldDisplay
Add the export helloworldDisplay file 添加导出helloworldDisplay文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.