Switch to Preact for Production builds

This commit is contained in:
kitajchuk
2021-06-10 08:19:23 -07:00
parent dda2e0b27e
commit 77b2a7b554
5 changed files with 24 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint
yarn build

View File

@@ -5,6 +5,10 @@ jambonz
![](/public/jambonz.png)
## Stack
This is a [Next.js](https://nextjs.org) application using [Preact](https://preactjs.com/) for Production builds which reduces JavaScript payload sizes by more than half for deployments! We're using a model that only uses Preact when generating the Production builds from this article [here](https://darrenwhite.dev/blog/nextjs-replace-react-with-preact).
## Deploy targets
This app can easily be deployed to multiple targets including Vercel, Netlify or AWS+circleci.

View File

@@ -1,3 +1,15 @@
module.exports = {
trailingSlash: true,
};
webpack: (config, { dev, isServer }) => {
// Replace React with Preact only in client production build
if (!dev && !isServer) {
Object.assign(config.resolve.alias, {
react: 'preact/compat',
'react-dom/test-utils': 'preact/test-utils',
'react-dom': 'preact/compat',
});
}
return config;
},
};

View File

@@ -18,6 +18,7 @@
"classnames": "^2.2.6",
"nanoid": "^3.1.22",
"next": "^10.0.8-canary.9",
"preact": "^10.5.13",
"prismjs": "^1.23.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",

View File

@@ -2209,6 +2209,11 @@ postcss@^7.0.32:
source-map "^0.6.1"
supports-color "^6.1.0"
preact@^10.5.13:
version "10.5.13"
resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.13.tgz#85f6c9197ecd736ce8e3bec044d08fd1330fa019"
integrity sha512-q/vlKIGNwzTLu+jCcvywgGrt+H/1P/oIRSD6mV4ln3hmlC+Aa34C7yfPI4+5bzW8pONyVXYS7SvXosy2dKKtWQ==
prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"