如何在没有Create-react-app的情况下创建React应用 [英] How to create a React App without Create-react-app
问题描述
我是React的新手,我使用create-react-app开发了一些应用程序来帮助我入门(随后提供了许多教程)。听说现在我需要知道如何从头开始创建一个React应用,而无需使用create-react-app样板制作程序。
I'm a newbie with React, I have made a few apps using the create-react-app to help get me started(as followed by numerous tutorials). I heard that I now need to know how to create a react app from scratch without using the create-react-app boilerplate maker.
我知道我必须添加一个一些部分,例如:
I know that i have to add a few sections such as:
- 反应
- 反应堆
- Webpack
- Babel
- React
- React-dom
- Webpack
- Babel
这是我package.json中的依赖项列表文件
here are the list of dependencies in my package.json file
"dependencies": {
"prop-types": "^15.6.1",
"react": "^16.4.0",
"react-dom": "^16.4.0"
},
"devDependencies": {
"babel": "^6.23.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"html-webpack-plugin": "^3.2.0",
"webpack": "^3.8.3",
"webpack-dev-server": "^3.1.4"
}
}
webpack.config.js
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: {
app:'./src/index',
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new HtmlWebpackPlugin(['app'])
],
module: {
loaders: [{
test:/\.js/ + /\.jsx?$/,
loader: 'babel-loader',
include: path.join(__dirname, 'src'),
}]
}
}
我的。 babelrc文件
My .babelrc file
{
"presents":["env","react"]
}
我遵循了一些有关如何从头开始制作React应用程序的教程,但是没有成功。我感觉我的Webpack配置不正确。
I've followed a few tutorials on how to make a React app from scratch, but with no success. I have a feeling that my Webpack config is not correct.
不幸的是,我仍然无法运行该项目
Unfortunately I am still unable to run this project
回购的Git链接:
https://github.com/tony2tones/scratch -react / tree / master
推荐答案
如前所述,您需要一个
index.js
其中至少需要: import from'react';
import ReactDOM from 'react-dom';
和
`ReactDOM.render(whatever you want to render, wherever you want to render(preferably document.getElementById('root')))
这显示了应用收到请求后应呈现的内容
This shows what the app should render when it gets a request
希望这会有所帮助。这是我的第一个答案:)
Hope this will help. it's my first answer :)
这篇关于如何在没有Create-react-app的情况下创建React应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!