From 1aa82c262f606c29eb516f6e70f036b6bf0e46e3 Mon Sep 17 00:00:00 2001 From: Jamie Brynes Date: Wed, 13 Mar 2024 19:49:35 +0000 Subject: [PATCH] chore: replace NODE_ENV at build time With react, it tries to read from process.env, but this fails on mobile leading to the plugin failing to load. By replacing this at build-time, we can sidestep this issue. --- plugin/package-lock.json | 50 ++++++++++++++++++++++++++++++++++++++++ plugin/package.json | 1 + plugin/vite.config.mts | 4 ++++ 3 files changed, 55 insertions(+) diff --git a/plugin/package-lock.json b/plugin/package-lock.json index 69b994c..7887b74 100644 --- a/plugin/package-lock.json +++ b/plugin/package-lock.json @@ -23,6 +23,7 @@ }, "devDependencies": { "@biomejs/biome": "^1.5.3", + "@rollup/plugin-replace": "^5.0.5", "@sveltejs/vite-plugin-svelte": "^3.0.2", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^14.2.1", @@ -2404,6 +2405,55 @@ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0" } }, + "node_modules/@rollup/plugin-replace": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.5.tgz", + "integrity": "sha512-rYO4fOi8lMaTg/z5Jb+hKnrHHVn8j2lwkqwyS4kTRhKyWOLf2wST2sWXr4WzWiTcoHTp2sTjqUbqIj2E39slKQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils/node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.10.0", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.10.0.tgz", diff --git a/plugin/package.json b/plugin/package.json index 739ac03..17c7678 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -27,6 +27,7 @@ }, "devDependencies": { "@biomejs/biome": "^1.5.3", + "@rollup/plugin-replace": "^5.0.5", "@sveltejs/vite-plugin-svelte": "^3.0.2", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^14.2.1", diff --git a/plugin/vite.config.mts b/plugin/vite.config.mts index 31805a3..9991a75 100644 --- a/plugin/vite.config.mts +++ b/plugin/vite.config.mts @@ -3,6 +3,7 @@ import { svelte } from "@sveltejs/vite-plugin-svelte"; import { viteStaticCopy } from "vite-plugin-static-copy"; import path, { resolve } from "path"; import { loadEnv } from "vite"; +import replace from '@rollup/plugin-replace'; function getOutDir(): string | undefined { const env = loadEnv("prod", process.cwd()); @@ -31,6 +32,9 @@ export default defineConfig({ }, ], }), + replace({ + "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV), + }) ], build: { // We aren't building a website, so we build in library mode