javascript - 如何使用 webpack 部署 MERN 项目

标签 javascript node.js reactjs webpack mern

我使用以下使用 webpack 的项目 https://github.com/Hashnode/mern-starter

我想将其部署(到产品),但出现错误

错误:找不到模块“./dist/manifest.json” 此错误来自https://github.com/Hashnode/mern-starter/blob/master/index.js

但是我在项目中没有看到 dist 文件夹,为什么,我应该如何构建它?

我认为应该在构建时创建 Dist 文件夹(manification 等)那么我应该如何触发它

这是package.json

{
  "name": "mern-starter",
  "version": "2.0.0",
  "description": "Boilerplate project for building Isomorphic apps using React and Redux",
  "scripts": {
    "test": "cross-env NODE_ENV=test PORT=8080 MONGO_URL=mongodb://localhost:27017/mern-test node_modules/.bin/nyc node --harmony-proxies node_modules/.bin/ava",
    "watch:test": "npm run test -- --watch",
    "cover": "nyc npm run test",
    "check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
    "start": "cross-env BABEL_DISABLE_CACHE=1 NODE_ENV=development nodemon index.js",
    "start:prod": "cross-env NODE_ENV=production node index.js",
    "bs": "npm run clean && npm run build && npm run build:server && npm run start:prod",
    "build": "cross-env NODE_ENV=production webpack --config webpack.config.prod.js",
    "build:server": "cross-env NODE_ENV=production webpack --config webpack.config.server.js",
    "clean": "rimraf dist",
    "slate": "rimraf node_modules && npm install",
    "lint": "eslint client server"
  }, 

我认为 start:prod 应该在 webpack 中触发它,但是 它没有发生......有什么想法吗?

最佳答案

根据评论和文档:

构建dist文件夹是通过npm run bsnpm run build && npm run build:server(这就是npm run bs 执行)。

开始生产构建应该通过 npm run start:prod 完成(或者通过从 package.json 文件复制命令:cross-env NODE_ENV =生产 Node index.js)

关于javascript - 如何使用 webpack 部署 MERN 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41417170/

相关文章:

javascript - jQuery 正则表达式验证

javascript - anchor 标记不适用于 Angular UI-Router

node.js - expressjs路由匹配特定的url

javascript - 在 React 中返回数组时如何添加换行符?

javascript - url 在 ahref 中不起作用,但在纯文本中起作用

javascript - 你如何将值从 html 中的迭代对象传递到 Angular2/4 中的组件?

javascript - javascript 中的简洁链接赋值运算符安全吗? (使变量无效)

javascript - 由于 CORS 选项预检,ReactJS 无法发送 POST 请求

angularjs - 如何将 AngularJS 中的文件和表单数据发送到 Node.js 服务器?

reactjs - React useState hook 如何处理可变对象