react html<h1>无效,在react项目中,使用js文件输出内容,为什么无效?

App.js

import React from 'react';

class App extends React.Component {

render() {

return React.createElement('div', null, `Hello ${this.props.toWhat}`);

}

}

ReactDOM.render(

React.createElement(App, {toWhat: 'World'}, null),

document.getElementById('root')

);

index.html

React App

main.js

import React from 'react';

import ReactDOM from 'react-dom';

//import App from './App.jsx';

import App from './App.js';

ReactDOM.render(, document.getElementById('app'))

package.json

{

"dependencies": {

"babel-core": "^6.26.0",

"react": "^15.6.1",

"react-dom": "^15.6.1"

},

"devDependencies": {

"babel-core": "^6.26.0",

"babel-loader": "^7.1.2",

"babel-plugin-transform-runtime": "^6.23.0",

"babel-preset-es2015": "^6.24.1",

"babel-preset-react": "^6.24.1",

"babel-preset-stage-2": "^6.24.1",

"express": "^4.15.4",

"html-webpack-plugin": "^2.30.1",

"react-hot-loader": "^1.3.1",

"webpack": "^3.6.0",

"webpack-dev-middleware": "^1.12.0",

"webpack-dev-server": "^2.8.2"

},

"name": "reactApp01",

"version": "1.0.0",

"main": "main.js",

"scripts": {

"build": "webpack",

"watch": "webpack --watch",

"start": "webpack-dev-server --hot --inline"

},

"keywords": [],

"author": "",

"license": "ISC",

"description": ""

}

webpack.config.js

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const webpack = require('webpack');

var config = {

//此处指明路口文件位置

entry: './main.js', //设置入口文件

//配置打包结果,

//path配置定义了输出的文件位置

//filename则定义了打包结果文件的名称

devtool: 'inline-source-map',

output: {//输出目录

filename: 'bundle.js',//设置导出文件为index.js

path: path.resolve(__dirname, 'dist')//打包后的js文件存放的地方

},

//设置本地服务器端口号为9001,此端口可以自己设定,但记住不能与其他服务端口重复

devServer:{

contentBase: './dist',//tell the dev server where to look for files

hot: true,

inline:true,

port:7700

},

plugins: [

new webpack.HotModuleReplacementPlugin()

],

//定义了对模块的处理逻辑,这里可以用loaders定义一系列的加载器,以及一些正则,

//当需要加载的文件匹配test的正则时,会调用后面的loader对文件进行处理,

//所以这就是webpack骚的可怕的地方。。。。。

module:{

loaders:[{

test:/\.jsx?$/,

exclude:/node_modules/,

loader:'babel-loader',

query:{

presets:['es2015','react']

}

}]

}

};

module.exports = config;

bVVv2t?w=1844&h=1048

修改完了,但是依然无效

import React from 'react';

class App extends React.Component {

render() {

return React.createElement('div', null, `Hello ${this.props.toWhat}`);

}

}

export default App;

bVVwIw?w=1370&h=926

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');

const webpack = require('webpack');

var config = {

//此处指明路口文件位置

entry: './main.js', //设置入口文件

//配置打包结果,

//path配置定义了输出的文件位置

//filename则定义了打包结果文件的名称

devtool: 'inline-source-map',

output: {//输出目录

filename: 'bundle.js',//设置导出文件为index.js

path: path.resolve(__dirname, 'dist')//打包后的js文件存放的地方

},

//设置本地服务器端口号为9001,此端口可以自己设定,但记住不能与其他服务端口重复

devServer:{

//contentBase: './dist',//tell the dev server where to look for files

hot: true,

inline:true,

port:7700

},

plugins: [

new webpack.HotModuleReplacementPlugin()

],

//定义了对模块的处理逻辑,这里可以用loaders定义一系列的加载器,以及一些正则,

//当需要加载的文件匹配test的正则时,会调用后面的loader对文件进行处理,

//所以这就是webpack骚的可怕的地方。。。。。

module:{

loaders:[{

test:/\.jsx?$/,

exclude:/node_modules/,

loader:'babel-loader',

query:{

presets:['es2015','react']

}

}]

}

};

module.exports = config;

bVVwWL?w=1332&h=868

bVVwZA?w=2338&h=1328

bVVwZX?w=1388&h=1052

bVVwZ3?w=1974&h=828

bVVw2v?w=1898&h=1050

bVVw9F?w=2338&h=1438

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值