From 4b95725e096b126408a83295d9132a06885c6034 Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Tue, 8 May 2018 17:52:52 +0800 Subject: [PATCH] fix(with-pkg): update pkg config for next.js (#4307) * fix(with-pkg): update pkg config for next.js * update docs --- examples/with-pkg/README.md | 16 ++++++++++------ examples/with-pkg/package.json | 7 +++---- examples/with-pkg/server.js | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/with-pkg/README.md b/examples/with-pkg/README.md index 152bb298..73422323 100644 --- a/examples/with-pkg/README.md +++ b/examples/with-pkg/README.md @@ -21,14 +21,18 @@ curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 cd with-pkg ``` -Install it and run: +Install it and run pkg: ```bash npm install -npm run dev -# or -yarn -yarn dev +yarn run build +yarn run dist +``` + +Execute the binary file: + +```bash +PORT=4000 ./dist/with-pkg-macos ``` Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) @@ -39,6 +43,6 @@ now ## The idea behind the example -This example demostrate how you can use [pkg](https://github.com/zeit/pkg) to create a binary version of a Next.js application. +This example demonstrate how you can use [pkg](https://github.com/zeit/pkg) to create a binary version of a Next.js application. To do it we need to create at least a super simple custom server that allow us to run `node server.js` instead of `next` or `next start`. We also need to create a `index.js` that works as the entry point for **pkg**, in that file we force to set NODE_ENV as production. diff --git a/examples/with-pkg/package.json b/examples/with-pkg/package.json index c1cb86d7..3a27d9ed 100644 --- a/examples/with-pkg/package.json +++ b/examples/with-pkg/package.json @@ -1,7 +1,7 @@ { "name": "with-pkg", "version": "1.0.0", - "main": "index.js", + "bin": "index.js", "author": "Sergio Daniel Xalambrí ", "license": "MIT", "scripts": { @@ -10,7 +10,7 @@ "prestart": "npm run build", "start": "NODE_ENV=production node server.js", "predist": "npm run build", - "dist": "pkg index.js --out-dir dist" + "dist": "pkg . --out-dir dist" }, "dependencies": { "next": "latest", @@ -22,8 +22,7 @@ }, "pkg": { "assets": [ - ".next", - "pages" + ".next/**/*" ], "scripts": [ ".next/dist/**/*.js" diff --git a/examples/with-pkg/server.js b/examples/with-pkg/server.js index 55dad515..40636d65 100644 --- a/examples/with-pkg/server.js +++ b/examples/with-pkg/server.js @@ -4,7 +4,7 @@ const next = require('next') const port = parseInt(process.env.PORT, 10) || 3000 const dev = process.env.NODE_ENV !== 'production' -const app = next({ dev }) +const app = next({ dev, dir: __dirname }) const handle = app.getRequestHandler() app.prepare()