Skip to content

feat: introduce built-in next.js exports and updated scripts and configs #5384

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 8 commits into from
May 18, 2023
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
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# Commonly ignored Node.js files
node_modules/
node_modules
npm-debug.log
.npm/
.npm

# OSX system files, the bane of our existence
.DS_Store
.AppleDouble
.LSOverride

# Next.js files
# Next.js Build Output
.next
build

# Next.js Generated Files
public/robots.txt
public/sitemap.xml
public/en/feed/*.xml
pages/en/blog/year-[0-9][0-9][0-9][0-9].md
Expand All @@ -26,8 +29,6 @@ coverage
# Storybook
storybook-static

# Vercel Config
# Vercel Files
.vercel

# TurboRepo
.turbo
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ npx turbo format

- `npx turbo serve` runs Next.js's Local Development Server, listening by default on `http://localhost:3000/`.
- `npx turbo build` builds the Application on Production mode. The output is by default within `.next` folder.
- `npx turbo export` exports the website from the `.next` into a fully static website. The output is by default within `build` folder.
- This is what it's used to deploy the website on our current Node.js servers.
- This is used for the Node.js Vercel Deployments (Preview & Production)
- `npx turbo deploy` builds the Application on Export Production Mode. The output is by default within `build` folder.
- This is used for the Node.js Legacy Website Server (DigitalOcean)
- `npx turbo start` starts a web server running serving the built content from `npx turbo build`

#### Other CLI options
Expand Down
16 changes: 0 additions & 16 deletions next-sitemap.config.js

This file was deleted.

26 changes: 26 additions & 0 deletions next-sitemap.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This is used for telling Next.js to to a Static Export Build of the Website
// We use this within this config file to determine the output directory of this generated sitemap files
const enableStaticExport = process.env.NEXT_STATIC_EXPORT === 'true';

/** @type {import('next-sitemap').IConfig} */
const sitemapConfig = {
siteUrl: 'https://nodejs.org',
changefreq: 'always',
trailingSlash: false,
generateRobotsTxt: true,
generateIndexSitemap: false,
outDir: enableStaticExport ? 'build' : 'public',
sourceDir: enableStaticExport ? 'build' : '.next',
output: enableStaticExport ? 'export' : undefined,
robotsTxtOptions: {
policies: [
{
userAgent: '*',
disallow: ['/dist/', '/docs/'],
allow: ['/dist/latest/', '/dist/latest/docs/api/', '/api/'],
},
],
},
};

export default sitemapConfig;
18 changes: 14 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ const withNextra = nextra({
},
});

const enableImageOptimization =
process.env.NEXT_ENABLE_IMAGE_OPTIMIZATION === 'true';
// This is used for telling Next.js to to a Static Export Build of the Website
// This is used for static/without a Node.js server hosting, such as on our
// legacy Website Build Environment on Node.js's DigitalOcean Droplet.
// Note.: Image optimization is also disabled through this process
const enableStaticExport = process.env.NEXT_STATIC_EXPORT === 'true';

// Supports a manuall override of the base path of the website
// This is useful when running the deployment on a subdirectory
// of a domain, such as when hosted on GitHub Pages.
const basePath = String(process.env.NEXT_BASE_PATH || '');

export default withNextra({
basePath,
trailingSlash: false,
images: { unoptimized: !enableImageOptimization },
outputFileTracing: false,
basePath: String(process.env.NEXT_BASE_PATH || ''),
distDir: enableStaticExport ? 'build' : '.next',
output: enableStaticExport ? 'export' : undefined,
images: { unoptimized: enableStaticExport },
});
67 changes: 34 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
"node": "v18"
},
"scripts": {
"serve": "cross-env NODE_ENV=development NODE_NO_WARNINGS=1 next dev",
"build": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 next build",
"postbuild": "next-sitemap",
"start": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 next start",
"export": "cross-env NODE_NO_WARNINGS=1 next export -o build",
"deploy": "npm run build && npm run export",
"serve": "cross-env NODE_NO_WARNINGS=1 next dev",
"build": "cross-env NODE_NO_WARNINGS=1 next build",
"start": "cross-env NODE_NO_WARNINGS=1 next start",
"deploy": "cross-env NEXT_STATIC_EXPORT=true npm run build && cross-env NEXT_STATIC_EXPORT=true npm run scripts:sitemap",
"lint:js": "eslint \"**/*.{js,jsx,ts,tsx}\" --cache --cache-file .eslintjscache --report-unused-disable-directives",
"lint:md": "eslint \"**/*.{md,mdx}\" --cache --cache-file .eslintmdcache",
"lint:scss": "stylelint --config .stylelintrc \"**/*.{css,sass,scss}\"",
Expand All @@ -25,13 +23,14 @@
"prettier": "prettier . --check --cache --cache-strategy metadata",
"prettier:fix": "npm run prettier -- --write",
"format": "npm run prettier:fix && npm run lint:fix",
"scripts:release-post": "NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
"test": "cross-env NODE_NO_WARNINGS=1 jest --passWithNoTests",
"test:watch": "npm run test -- --watch",
"test:ci": "npm run test -- --coverage",
"test:watch": "npm run test -- --watch",
"test:snapshot": "npm run test -- --updateSnapshot",
"storybook": "cross-env NODE_ENV=development NODE_NO_WARNINGS=1 storybook dev -p 6006",
"storybook:build": "cross-env NODE_ENV=production NODE_NO_WARNINGS=1 storybook build"
"storybook": "cross-env NODE_NO_WARNINGS=1 storybook dev -p 6006",
"storybook:build": "cross-env NODE_NO_WARNINGS=1 storybook build",
"scripts:release-post": "cross-env NODE_NO_WARNINGS=1 node scripts/release-post/index.mjs",
"scripts:sitemap": "cross-env NODE_NO_WARNINGS=1 next-sitemap --config next-sitemap.config.mjs"
},
"dependencies": {
"@mdx-js/react": "^2.3.0",
Expand All @@ -45,7 +44,7 @@
"highlight.js": "^11.8.0",
"isomorphic-dompurify": "^1.3.0",
"next": "^13.3.4",
"next-sitemap": "^4.0.9",
"next-sitemap": "^4.1.3",
"next-themes": "^0.2.1",
"nextra": "^2.4.2",
"node-version-data": "^1.1.0",
Expand Down Expand Up @@ -103,7 +102,7 @@
"stylelint-config-recommended-scss": "^11.0.0",
"stylelint-order": "^6.0.3",
"stylelint-selector-bem-pattern": "^2.1.1",
"turbo": "^1.9.3",
"turbo": "^1.9.8",
"typescript": "^5.0.4"
}
}
13 changes: 0 additions & 13 deletions public/robots.txt

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/next-data/generatePreBuildFiles.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @TODO: This is a temporary hack until we migrate to the `nodejs/nodejs.dev` codebase
import { writeFile } from 'fs/promises';
import { join } from 'path';
import { writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { Feed } from 'feed';

import { getRelativePath } from './_helpers.mjs';
Expand Down
4 changes: 2 additions & 2 deletions scripts/next-data/getBlogData.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile, readdir } from 'fs/promises';
import { basename, extname, join } from 'path';
import { readFile, readdir } from 'node:fs/promises';
import { basename, extname, join } from 'node:path';
import graymatter from 'gray-matter';

import {
Expand Down
8 changes: 4 additions & 4 deletions scripts/next-data/getLocalisationData.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readdirSync } from 'fs';
import { readFile } from 'fs/promises';
import { basename, extname, join } from 'path';
import { fileURLToPath } from 'url';
import { readdirSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { basename, extname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

// this allows us to get the current module working directory
const __dirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down
8 changes: 4 additions & 4 deletions scripts/release-post/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

'use strict';

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';
import handlebars from 'handlebars';
import { fileURLToPath } from 'node:url';

import downloadsTable from './downloadsTable.mjs';
import { getRelativePath } from '../next-data/_helpers.mjs';
Expand Down Expand Up @@ -259,7 +259,7 @@ export {

// This allows us to verify that the script is being run directly from node.js/cli
if (import.meta.url.startsWith('file:')) {
const modulePath = fileURLToPath(import.meta.url);
const modulePath = url.fileURLToPath(import.meta.url);

if (process.argv[1] === modulePath) {
explicitVersion(process.argv[2])
Expand Down
4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"tsconfig.json",
"next.config.mjs",
"next.data.mjs",
"next-sitemap.config.js",
"next-sitemap.config.mjs",
"theme.tsx",
"middleware.ts"
],
Expand All @@ -76,7 +76,7 @@
"tsconfig.json",
"next.config.mjs",
"next.data.mjs",
"next-sitemap.config.js",
"next-sitemap.config.mjs",
"theme.tsx",
"middleware.ts"
],
Expand Down