如何运行React应用程序的构建?

时间:2018-03-08 09:58:17

标签: reactjs

我使用npm run-script build为React应用做了一个构建,我需要运行它。使用npm run webpack返回错误。请原谅我对React很新,但我真的需要知道如何运行这个应用程序。希望你能帮忙!

我的package.json:

{
"name": "dashboard",
"version": "0.1.0",
"private": true,
"dependencies": {
    "axios": "^0.16.2",
    "downloadjs": "^1.4.7",
    "fast-memoize": "^2.2.8",
    "flow-bin": "^0.52.0",
    "lodash": "^4.17.4",
    "mapbox-gl": "^0.39.1",
    "material-ui": "^0.18.7",
    "moment": "^2.18.1",
    "node-sass-chokidar": "^0.0.3",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-mapbox-gl": "^2.5.0",
    "react-redux": "^5.0.5",
    "react-router": "^4.1.2",
    "react-router-dom": "^4.1.2",
    "react-router-redux": "next",
    "react-tap-event-plugin": "^2.0.1",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0"
},
"devDependencies": {
    "react-emotion": "^7.2.2",
    "react-scripts": "1.0.10",
    "styled-components": "^2.1.2"
},
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "flow": "flow"
}

Here are the folders and files of the built app

3 个答案:

答案 0 :(得分:0)

您使用的是create-react-app吗?如果是,则运行" npm run build"在根文件夹中。此命令将运行您的应用程序

答案 1 :(得分:0)

通过查看"react-scripts": "1.0.10",您似乎使用create-react-app创建了应用。

默认情况下,

create-react-app 正在使用 yarn 。因此,您可以yarn然后yarn build(与npm install相同,然后npm run build

如果您需要更改webpack配置。该应用首先弹出。你可以yarn eject来做。然后你可以编辑webpack配置文件。

这有帮助吗?

答案 2 :(得分:0)

正如我在评论中提到的那样。

npm run build使用react-scripts为您创建构建

在生产中运行:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "flow": "flow",
    "start:prod": 'node dist/app.js'
}