Skip to content

Commit ff04e64

Browse files
authored
Merge pull request #170 from aws-samples/migrate-to-next
Add NextJS and Typescript to the frontend
2 parents eb8cc01 + da9f980 commit ff04e64

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6358
-27692
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
__pycache__
22
frontend/node_modules
3+
frontend/.next
4+
frontend/.swc
5+
frontend/build
36
infrastructure/cognitolambda/node_modules
47
.DS_Store
58
.hugo_build.lock

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Start the React frontend by running:
111111
```bash
112112
cd frontend/
113113
npm install # if this is your first time starting the frontend
114-
npm start
114+
npm run dev
115115
```
116116

117117
Then navigate to [http://localhost:3000](http://localhost:3000)

frontend/.babelrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file is only here to disable SWC, which is currently broken
2+
// and causes AppLayout to go into an infinite loop, firing a
3+
// RangeError: Maximum call stack size exceeded
4+
//
5+
// Next allegedly already fixed this problem with this PR:
6+
// https://github.com/vercel/next.js/pull/37607
7+
// therefore we can probably remove this file in the future
8+
{
9+
"presets": ["next/babel"]
10+
}

frontend/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
node_modules
2+
.next
3+
.swc
4+
build

frontend/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

frontend/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

frontend/Dockerfile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# build environment
2-
FROM node:13.12.0-alpine as build
1+
# Install dependencies
2+
FROM node:16-alpine as deps
33
WORKDIR /app
4-
ENV PATH /app/node_modules/.bin:$PATH
5-
ARG PUBLIC_URL=
64
COPY package.json ./
75
COPY package-lock.json ./
86
RUN npm ci
9-
RUN npm install react-scripts@3.4.1 -g
10-
COPY . ./
11-
RUN npm install
12-
RUN npm run build
7+
8+
# Build source code
9+
FROM node:16-alpine AS builder
10+
WORKDIR /app
11+
COPY --from=deps /app/node_modules ./node_modules
12+
COPY . .
13+
# Disable telemetry
14+
# Next.js collects completely anonymous telemetry data about general usage.
15+
# Learn more here: https://nextjs.org/telemetry
16+
ENV NEXT_TELEMETRY_DISABLED 1
17+
RUN npm run export

frontend/next-env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

frontend/next.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
3+
// with the License. A copy of the License is located at
4+
//
5+
// http://aws.amazon.com/apache2.0/
6+
//
7+
// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
8+
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
9+
// limitations under the License.
10+
11+
/** @type {import('next').NextConfig} */
12+
const nextConfig = {
13+
reactStrictMode: true,
14+
async rewrites() {
15+
return [
16+
/**
17+
* Rewrite everything to `pages/index`
18+
*
19+
* This is only here because as of yet we are not
20+
* relying on NextJS routing and react-router-dom
21+
* does not play well with SSR.
22+
*
23+
* While doing the transition to NextJS routing,
24+
* we need a way to support both ways of functioning.
25+
*
26+
* Please note, this is only useful in the context of
27+
* local development (`npm run dev`), as this app is
28+
* currently being built as a static export
29+
* and no rewrite is going to be actually run in production
30+
*/
31+
{
32+
source: "/:any*",
33+
destination: "/",
34+
},
35+
];
36+
},
37+
}
38+
39+
const withTM = require("next-transpile-modules")([
40+
"@awsui/components-react",
41+
]);
42+
43+
module.exports = withTM(nextConfig);

0 commit comments

Comments
 (0)