From eaeebdc24230be5f08ab84055342d8ba5711bbee Mon Sep 17 00:00:00 2001 From: Jon Koops Date: Wed, 14 Jul 2021 14:17:57 +0200 Subject: [PATCH] Use a Snowpack plugin to enable React Fast Refresh (#845) --- package-lock.json | 1 + package.json | 1 + snowpack.config.js | 6 +++++- src/index.tsx | 6 ++++++ tsconfig.json | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 78b0f4bea6..11dbb03364 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "@jest/types": "^27.0.6", "@snowpack/app-scripts-react": "^1.12.6", "@snowpack/plugin-postcss": "1.4.3", + "@snowpack/plugin-react-refresh": "^2.5.0", "@snowpack/plugin-typescript": "^1.2.1", "@snowpack/plugin-webpack": "3.0.0", "@storybook/addon-actions": "^6.3.4", diff --git a/package.json b/package.json index 7ebbede0b1..8c0b6efb8d 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "@jest/types": "^27.0.6", "@snowpack/app-scripts-react": "^1.12.6", "@snowpack/plugin-postcss": "1.4.3", + "@snowpack/plugin-react-refresh": "^2.5.0", "@snowpack/plugin-typescript": "^1.2.1", "@snowpack/plugin-webpack": "3.0.0", "@storybook/addon-actions": "^6.3.4", diff --git a/snowpack.config.js b/snowpack.config.js index 6140a0ae7f..1791490707 100644 --- a/snowpack.config.js +++ b/snowpack.config.js @@ -3,7 +3,11 @@ module.exports = { proxy: { "/auth/admin": "http://localhost:8180/auth/admin/", }, - plugins: ["@snowpack/plugin-postcss", "@snowpack/plugin-typescript"], + plugins: [ + "@snowpack/plugin-postcss", + "@snowpack/plugin-react-refresh", + "@snowpack/plugin-typescript", + ], buildOptions: { baseUrl: "/adminv2", clean: true, diff --git a/src/index.tsx b/src/index.tsx index 9afcbc3aef..4153ea5bfa 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,3 +13,9 @@ init().then((adminClient) => { document.getElementById("app") ); }); + +// Hot Module Replacement (HMR) - Remove this snippet to remove HMR. +// Learn more: https://snowpack.dev/concepts/hot-module-replacement +if (import.meta.hot) { + import.meta.hot.accept(); +} diff --git a/tsconfig.json b/tsconfig.json index 885daf5a06..bfdcedc093 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "@snowpack/app-scripts-react/tsconfig.base.json", "compilerOptions": { - "types": ["jest", "cypress"], + "types": ["jest", "cypress", "snowpack-env"], "esModuleInterop": true } } \ No newline at end of file