Skip to content

Commit

Permalink
chore: add basePath to next.config.js for github pages deployment and…
Browse files Browse the repository at this point in the history
… use es modules
  • Loading branch information
AlexanderMelde committed Mar 3, 2024
1 parent 9a1da04 commit efe51bc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 52 deletions.
13 changes: 8 additions & 5 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/**
* @type {import('next').NextConfig}
*/
/** @type {import('next').NextConfig} */

const isProd = process.env.NODE_ENV === 'production';
export const basePath = isProd ? '/klimadashboard-ka' : '';

const nextConfig = {
output: 'export',

basePath,

images: {
unoptimized: true
}
}

module.exports = nextConfig
export default nextConfig;
4 changes: 0 additions & 4 deletions next.config.mjs

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "klimadashboard-ka",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "cross-env NODE_ENV=production next build",
Expand Down
6 changes: 0 additions & 6 deletions postcss.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions postcss.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": {
"tailwindcss": {},
"autoprefixer": {}
}
}
30 changes: 8 additions & 22 deletions src/app/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,22 @@

import useSWR from "swr";
import {FeinstaubDataEntry, GreenHouseGasEntry, SensorDataEntryJSON} from "@/app/api/models";
import {basePath} from "../../next.config";

const fetcher = (
input: URL | RequestInfo,
init?: RequestInit | undefined,
) => fetch(input, init).then((res) => res.json());
const fetcher = (input: URL | RequestInfo, init?: RequestInit | undefined) => fetch(input, init).then((res) => res.json());

export function useData1(): {
data: { data: SensorDataEntryJSON[] },
isLoading: boolean,
isError: boolean,
} {
const {data, error, isLoading} = useSWR(`/api/test-data`, fetcher);
export function useData1(): { data: { data: SensorDataEntryJSON[] }; isLoading: boolean; isError: boolean } {
const {data, error, isLoading} = useSWR(`${basePath}/api/test-data`, fetcher);
return {data, isLoading, isError: error};
}

export function useData3(): {
data: { data: FeinstaubDataEntry[] },
isLoading: boolean,
isError: boolean,
} {
const {data, error, isLoading} = useSWR(`/api/test-data3`, fetcher);
export function useData3(): { data: { data: FeinstaubDataEntry[] }; isLoading: boolean; isError: boolean } {
const {data, error, isLoading} = useSWR(`${basePath}/api/test-data3`, fetcher);
return {data, isLoading, isError: error};
}

export function useData4(): {
data: { data: GreenHouseGasEntry[] },
isLoading: boolean,
isError: boolean,
} {
const {data, error, isLoading} = useSWR(`/api/test-data4`, fetcher);
export function useData4(): { data: { data: GreenHouseGasEntry[] }; isLoading: boolean; isError: boolean } {
const {data, error, isLoading} = useSWR(`${basePath}/api/test-data4`, fetcher);
return {data, isLoading, isError: error};
}

30 changes: 15 additions & 15 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { Config } from "tailwindcss";
import type {Config} from "tailwindcss";

const config: Config = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
},
},
},
},
plugins: [],
plugins: [],
};
export default config;

0 comments on commit efe51bc

Please sign in to comment.