简体   繁体   English

Node.js启动React-App客户端

[英]nodejs start react-app client

I've made a web app using create-react-app which works fine, and I usually run it using npm start but now I have to deploy it and make it work with nodejs forever module. 我已经使用create-react-app制作了一个网络应用create-react-app ,该create-react-app运行良好,并且通常使用npm start运行它,但是现在我必须对其进行部署,并使其与forever nodejs模块一起使用。

If I do node src/index.js it will give a syntax error and to fix this I used babel to transpile es6 to es5 , but again I get the following syntax error when importing the css file: 如果我执行node src/index.js ,它将给出语法错误并解决此问题,我使用babel将es6 es6es5 ,但是再次在导入css文件时出现以下语法错误:

/client/src/stylesheets/menu.css:1
(function (exports, require, module, __filename, __dirname) { header {
                                                                     ^

SyntaxError: Unexpected token {

This is my package.json file: 这是我的package.json文件:

{
  "dependencies": {
    "async": "^2.5.0",
    "axios": "^0.16.2",
    "classnames": "^2.2.5",
    "date-diff": "^0.1.3",
    "jwt-decode": "^2.2.0",
    "lodash": "^4.17.4",
    "react": "^15.6.1",
    "react-bootstrap": "^0.31.2",
    "react-bootstrap-table": "^4.0.2",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.0.12",
    "react-select": "^1.0.0-rc.5",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "shortid": "^2.2.8",
    "validator": "^8.1.0"
  },
  "scripts": {
    "start": "react-scripts-with-stylus start src/stylesheets/menu.styl",
    "build": "react-scripts-with-stylus build src/stylesheets/menu.styl",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:8081",
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-cli": "^6.24.1",
    "babel-core": "^6.25.0",
    "babel-polyfill": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "create-react-app-stylus": "^1.1.1",
    "webpack": "^3.5.5"
  }
}

To sum up the answer to this question: 总结这个问题的答案:

  • If you need to deploy it, you should make a build, not run your application directly. 如果需要部署它,则应该进行构建,而不是直接运行应用程序。
  • run npm run build and it will generate build files into a new folder. 运行npm run build ,它将生成构建文件到一个新文件夹中。
  • You should not try to run the application with npm at all. 您根本不应该尝试使用npm运行该应用程序。 You should copy all the files from the build folder into the root of your server and when a user opens the page it will be shown index.html file. 您应该将所有文件从build文件夹复制到服务器的根目录中,当用户打开页面时,将显示index.html文件。
  • If your code has changed and is ready for production you can rebuild it, or you can automate this process with some CI tool. 如果您的代码已更改并且可以投入生产,则可以对其进行重建,也可以使用某些CI工具自动执行此过程。
  • You should only have React client files on your Git repository, build files should be generated during the build process on your server. 您应该仅在Git存储库中具有React客户端文件,构建文件应在服务器上的构建过程中生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM