Skip to content

feat: merge next-on-netlify into the core plugin repo #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ __mocks__
test/fixtures
test/sample
next.config.js
src/cypress/builds/
src/tests/builds/
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 3.0.0 (2021-03-??)

- feat: merge `next-on-netlify` into `@netlify/plugin-nextjs`

This improves our ability to maintain the plugin, reduces confusion about how to configure Next.js support for Netlify builds, and prepares the plugin for something we're pretty dang excited about: automatic installation for new Next.js projects!

> **NOTE: There are no breaking changes for existing plugin users.** This is a major release because we're bringing an external package into the plugin _and_ turning on automatic installation for new Next.js projects on Netlify. This doesn't break anything, but it's a big enough change that we wanted to treat it as a major release.
### Migrating from v2 to v3

If you've installed this plugin via Netlify's UI, no action is necessary. The upgrade is automatic.

If you've installed this plugin manually in your `netlify.toml`, you can upgrade two ways:

1. Manually update to the latest version using `npm i @netlify/plugin-nextjs@latest`.
2. If you prefer to automatically get updates, remove this plugin from your project and `netlify.toml`, then [install the plugin using the Netlify UI](http://app.netlify.com/plugins/@netlify/plugin-nextjs/install).

### Migrating from the original `next-on-netlify` package

As part of the 3.0.0 release, `next-on-netlify` has been deprecated and merged into the Essential Next.js Build Plugin. If your site is using the `next-on-netlify` package, you'll need to switch over to the plugin to get future updates.

For instructions on migrating from `next-on-netlify` to the Essential Next.js Build Plugin, please see the [migration guide on the `next-on-netlify` repo](https://github.com/netlify/next-on-netlify/blob/main/MIGRATING.md).

## 2.0.1 (2021-02-17)

- fail build if plugin cant load next.config.js ([#99](https://github.com/netlify/netlify-plugin-nextjs/pull/99))
Expand Down
58 changes: 31 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Next.js on Netlify Build Plugin](next-on-netlify.png)

# Next.js Build Plugin
# Essential Next.js Build Plugin

<p align="center">
<a aria-label="npm version" href="https://www.npmjs.com/package/@netlify/plugin-nextjs">
Expand All @@ -26,46 +26,50 @@ This build plugin is a utility for supporting Next.js on Netlify. To enable serv

## Installation and Configuration

There are two ways to install the plugin in your Next.js on Netlify site: with the Netlify UI or with file-based installation.
### For new Next.js sites

**UI-based Installation**
As of v3.0.0, all new sites deployed to Netlify with Next.js will automatically install this plugin for a seamless experience deploying Next.js on Netlify!

You can install this plugin using this [direct in-app installation link](http://app.netlify.com/plugins/@netlify/plugin-nextjs/install) or from your team's [Plugins directory](https://app.netlify.com/plugins) in the Netlify UI.
This means that you don't have to do anything — just build and deploy your site to Netlify as usual and we'll handle the rest.

Read more about [UI-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#ui-installation) in our docs.
You're able to [remove the plugin](https://docs.netlify.com/configure-builds/build-plugins/#remove-a-plugin) at any time by visiting the **Plugins** tab for your site in the Netlify UI.

**File-based Installation**
### UI-based installation for existing Next.js sites

1. Create a `netlify.toml` in the root of your project. Your file should include the plugins section below:
If your Next.js project is already deployed to Netlify, use the Netlify UI to [install the Essential Next.js Build Plugin](http://app.netlify.com/plugins/@netlify/plugin-nextjs/install) in a few clicks.

```toml
[build]
command = "npm run build"
publish = "out"
### Manual installation

[[plugins]]
package = "@netlify/plugin-nextjs"
```
1\. Create a `netlify.toml` in the root of your project. Your file should include the plugins section below:

```toml
[build]
command = "npm run build"
publish = "out"

[[plugins]]
package = "@netlify/plugin-nextjs"
```

You can also add context-specific properties and environment variables to your `netlify.toml`. Read more about [deploy contexts](https://docs.netlify.com/configure-builds/file-based-configuration/#deploy-contexts) in our docs. For example:

```toml
[context.production.environment]
NEXT_SERVERLESS = "true"
NODE_ENV = "production"
```
```toml
[context.production.environment]
NEXT_SERVERLESS = "true"
NODE_ENV = "production"
```

2. From your project's base directory, use `npm`, `yarn`, or any other Node.js package manager to add this plugin to `devDependencies` in `package.json`.
2\. From your project's base directory, use `npm`, `yarn`, or any other Node.js package manager to add this plugin to `devDependencies` in `package.json`.

```
npm install -D @netlify/plugin-nextjs
```
```
npm install -D @netlify/plugin-nextjs
```

or
or

```
yarn add -D @netlify/plugin-nextjs
```
```
yarn add -D @netlify/plugin-nextjs
```

Read more about [file-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#file-based-installation) in our docs.

Expand Down
2 changes: 1 addition & 1 deletion helpers/doesNotNeedPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const doesNotNeedPlugin = async ({ netlifyConfig, packageJson, utils }) => {
return (
isStaticExportProject({ build, scripts }) ||
doesSiteUseNextOnNetlify({ packageJson }) ||
!hasCorrectNextConfig({ nextConfigPath, failBuild: utils.build.failBuild })
!(await hasCorrectNextConfig({ nextConfigPath, failBuild: utils.build.failBuild }))
)
}

Expand Down
4 changes: 2 additions & 2 deletions helpers/hasCorrectNextConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')

// Checks if site has the correct next.cofig.js
const hasCorrectNextConfig = ({ nextConfigPath, failBuild }) => {
const hasCorrectNextConfig = async ({ nextConfigPath, failBuild }) => {
// In the plugin's case, no config is valid because we'll make it ourselves
if (nextConfigPath === undefined) return true

Expand All @@ -14,7 +14,7 @@ const hasCorrectNextConfig = ({ nextConfigPath, failBuild }) => {
const acceptableTargets = ['serverless', 'experimental-serverless-trace']
let nextConfig
try {
nextConfig = loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
nextConfig = await loadConfig(PHASE_PRODUCTION_BUILD, path.resolve('.'))
} catch (error) {
return failBuild('Error loading your next.config.js.', { error })
}
Expand Down
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const util = require('util')
const makeDir = require('make-dir')
const findUp = require('find-up')
const nextOnNetlify = require('./src/index.js')

const validateNextUsage = require('./helpers/validateNextUsage')
const doesNotNeedPlugin = require('./helpers/doesNotNeedPlugin')
Expand Down Expand Up @@ -53,11 +54,7 @@ module.exports = {

await makeDir(PUBLISH_DIR)

// We cannot load `next-on-netlify` (which depends on `next`) at the
// top-level because we validate whether the site is using `next`
// inside `onPreBuild`.
const nextOnNetlify = require('next-on-netlify')
nextOnNetlify({ functionsDir: FUNCTIONS_SRC, publishDir: PUBLISH_DIR })
await nextOnNetlify({ functionsDir: FUNCTIONS_SRC, publishDir: PUBLISH_DIR })
},
}

Expand Down
Loading