如何在没有 Create-react-app 的情况下创建 React App

ton*_*nes 8 boilerplate reactjs webpack create-react-app

我是 React 的新手,我使用 create-react-app 制作了一些应用程序来帮助我入门(随后是大量教程)。我听说我现在需要知道如何在不使用 create-react-app 样板制作器的情况下从头开始创建 React 应用程序。

我知道我必须添加一些部分,例如:

  • 反应
  • React-dom
  • 网络包
  • 通天塔

这是我的 package.json 文件中的依赖项列表

"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"
  }
}
Run Code Online (Sandbox Code Playgroud)

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'),
        }]
    }
}
Run Code Online (Sandbox Code Playgroud)

我的 .babelrc 文件

{
    "presents":["env","react"]
}
Run Code Online (Sandbox Code Playgroud)

我已经学习了一些关于如何从头开始制作 React 应用程序的教程,但没有成功。我有一种感觉,我的 Webpack 配置不正确。

不幸的是我仍然无法运行这个项目

仓库的 Git 链接:https : //github.com/tony2tones/scratch-react/tree/master

Mah*_*pal 0

看来你错过了一些东西。

  1. 对于build您的项目,您可以调用npm run build.
  2. 您需要添加一个index.html要在浏览器中呈现的文件。
  3. 您需要start在里面添加您的脚本对象package.jsonnpm install再次执行。

对于3,您可以添加,"start": "webpack-dev-server" 然后运行您的节点服务器,您可以通过npm run start

希望这可以帮助。