开发者问题收集

转译 next.js 服务器代码

2017-05-19
1289

我全新安装了 Next.js,并且希望能够使用 importasync/await 等。

我已更新 .babelrc

{
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["."],
        "alias": {
          "styles": "./styles"
        },
        "cwd": "babelrc"
      }
    ],
    [
      "wrap-in-js",
      {
        "extensions": ["css$"]
      }
    ]
  ],
  "presets": [
    "next/babel",
    "es2015",
    "stage-0",
  ],
  "ignore": []
}

我假设我需要将一些配置更新到 ./server.js

此外,我该如何启动我的应用程序,因为我可以指向我的启动脚本从 ./dist/server 运行,但我相信服务器需要运行才能运行构建?

1个回答

I have a fresh install of Next.js and am wanting to be able to use import and async/await etc.

我相信 async/await 可以在当前版本上运行而无需修改,但动态导入需要 v3 beta:

npm install next.js@beta

请参阅 https://zeit.co/blog/next3-preview

Also how do I get around starting my app as I can point my start script to run from ./dist/server but I believe the server needs to run to be able to run a build?

通常,在开发时运行 npm run dev (别名为 next ),在生产时运行 npm run build; npm start (别名为 next build; next start )。您不会直接运行任何 JS 文件。

如果您想运行自定义服务器,则可以直接启动服务器文件( node myserver.js 或其他文件),然后以编程方式启动它。有关更多信息,请参阅 https://github.com/zeit/next.js/tree/master#custom-server-and-routing

Nathan Friedly
2017-06-29