Skip to content
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

Remove Framer Motion and switch to Preact on Production #171

Merged
merged 4 commits into from
Oct 27, 2022
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
26 changes: 2 additions & 24 deletions components/elements/Container.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
import { useRouter } from "next/router";
import { meta as head_meta, feautures, social } from "@/config";
import { motion, useReducedMotion } from "framer-motion";
import { meta as head_meta, social } from "@/config";
import { Nav } from "@components/elements/Nav";
import { Footer } from "@components/elements/Footer";
import Head from "next/head";
import Twemoji from "react-twemoji";

export function Container(props) {
const { children, ...customMeta } = props;
const reduceMotion = useReducedMotion();
const router = useRouter();
const meta = {
...head_meta,
...customMeta,
};

const variants = {
initial: {
scale: reduceMotion ? 1 : 0.96,
y: reduceMotion ? 0 : 15,
opacity: 1,
},
animate: {
y: 0,
scale: 1,
opacity: 1,
},
exit: {
y: reduceMotion ? 0 : 15,
opacity: 1,
transition: {
duration: reduceMotion ? 0 : 0.2,
},
},
};

return (
<>
<Head>
Expand All @@ -58,7 +36,7 @@ export function Container(props) {
</Head>
<Nav />
<main className="mt-24 flex min-h-screen flex-col antialiased">
<Twemoji options={{ className: "twemoji" }}>{feautures.smoothTransition ? <motion.div {...variants}>{children}</motion.div> : children}</Twemoji>
<Twemoji options={{ className: "twemoji" }}>{children}</Twemoji>
</main>
<Footer />
</>
Expand Down
100 changes: 42 additions & 58 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** @type {import('next').NextConfig} */
const { withContentlayer } = require("next-contentlayer");
const withPWA = require("next-pwa");
const CompressionPlugin = require("compression-webpack-plugin");
Expand All @@ -21,22 +20,44 @@ const nextConfig = {
poweredByHeader: false,
trailingSlash: false,
compress: true,
swcMinify: true,
/*experimental: {
legacyBrowsers: false,
browsersListForSwc: true,
fontLoaders: [{ loader: "@next/font/google", options: { subsets: ["latin"] } }],
},*/
images: {
domains: [
"github.githubassets.com", // GitHub assets
],
swcMinify: false,
experimental: {
appDir: true,
},
async headers() {
return [
{
source: "/(.*)",
headers: securityHeaders,
headers: [
{
key: "Referrer-Policy",
value: "no-referrer",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "X-DNS-Prefetch-Control",
value: "on",
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains; preload",
},
{
key: "Cache-Control",
value: "public, max-age=21600, must-revalidate",
},
{
key: "X-XSS-Protection",
value: "1; mode=block",
},
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=()",
},
],
},
{
source: "/*.xml",
Expand Down Expand Up @@ -90,6 +111,12 @@ const nextConfig = {
},
webpack: (config, { isServer, dev }) => {
if (!dev && !isServer) {
Object.assign(config.resolve.alias, {
"react/jsx-runtime.js": "preact/compat/jsx-runtime",
react: "preact/compat",
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
});
config.plugins.push(
new CompressionPlugin(),
new LodashModuleReplacementPlugin(),
Expand All @@ -108,52 +135,9 @@ module.exports = () => {
const plugins = [withPWA, withContentlayer, withBundleAnalyzer];
const config = plugins.reduce((acc, next) => next(acc), {
...nextConfig,
experimental: {
appDir: true,
},
});
return config;
};

const ContentSecurityPolicy = `
default-src 'self' *.googletagmanager.com *.arc.io;
script-src 'self' 'unsafe-eval' 'unsafe-inline' *.googletagmanager.com arc.io *.arc.io *.sentry-cdn.com;
child-src 'self' *.youtube.com *.google.com *.twitter.com *.arc.io;
style-src 'self' 'unsafe-inline' *.googleapis.com *.arc.io *.cloudflare.com;
img-src * blob: data:;
media-src 'none';
connect-src *;
font-src 'self' *.googleapis.com *.gstatic.com *.arc.io;
`;

const securityHeaders = [
//{
// key: "Content-Security-Policy",
// value: ContentSecurityPolicy.replace(/\n/g, ""),
// },
{
key: "Referrer-Policy",
value: "no-referrer",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
{
key: "X-DNS-Prefetch-Control",
value: "on",
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains; preload",
},
{
key: "Cache-Control",
value: "public, max-age=300, must-revalidate",
},
{
key: "X-XSS-Protection",
value: "1; mode=block",
},
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=()",
},
];
23 changes: 19 additions & 4 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "igorkowalczyk-portfolio",
"description": "My portfolio built on Next.js",
"version": "2.6.0",
"version": "2.7.0",
"private": true,
"scripts": {
"start": "next start",
Expand Down Expand Up @@ -34,8 +34,9 @@
"next-pwa": "^5.6.0",
"next-themes": "^0.2.1",
"nprogress": "^0.2.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"preact": "^10.11.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-ga4": "^1.4.1",
"react-github-calendar": "^3.3.4",
"react-markdown": "^8.0.3",
Expand Down
7 changes: 1 addition & 6 deletions pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ThemeProvider } from "next-themes";
import { Analytics } from "@vercel/analytics/react";
import { Router } from "next/router";
import { AnimatePresence, MotionConfig } from "framer-motion";
import { GoogleAnalytics } from "@lib/analytics";
import nProgress from "nprogress";
import "@styles/globals.css";
Expand All @@ -18,11 +17,7 @@ export default function App({ Component, pageProps, router }) {
return (
<>
<ThemeProvider attribute="class" themes={["light", "dark"]} defaultTheme="system">
<MotionConfig reducedMotion="user">
<AnimatePresence mode="wait">
<Component {...pageProps} key={router.route} />
</AnimatePresence>
</MotionConfig>
<Component {...pageProps} key={router.route} />
</ThemeProvider>
<Analytics />
</>
Expand Down
2 changes: 1 addition & 1 deletion public/feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<description><![CDATA[Igor Kowalczyk]]></description>
<link>https://igorkowalczyk.dev</link>
<generator>RSS for Node</generator>
<lastBuildDate>Wed, 26 Oct 2022 19:14:46 GMT</lastBuildDate>
<lastBuildDate>Thu, 27 Oct 2022 18:50:45 GMT</lastBuildDate>
<atom:link href="https://igorkowalczyk.dev/feed.xml" rel="self" type="application/rss+xml"/>
<item>
<title><![CDATA[How I built my website]]></title>
Expand Down