Created
January 4, 2023 20:51
-
-
Save airhorns/d312911de21e61084c2ac9595a3bc98c to your computer and use it in GitHub Desktop.
Final vite.config.js code for Gadget + Shopify CLI app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineConfig } from "vite"; | |
import { dirname } from "path"; | |
import { fileURLToPath } from "url"; | |
import react from "@vitejs/plugin-react"; | |
if (process.env.npm_lifecycle_event === "build" && !process.env.CI && !process.env.SHOPIFY_API_KEY) { | |
console.warn( | |
"\nBuilding the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.\n" | |
); | |
} | |
const proxyOptions = { | |
target: `http://127.0.0.1:${process.env.BACKEND_PORT}`, | |
changeOrigin: false, | |
secure: true, | |
ws: false, | |
}; | |
const hmrConfig = { | |
protocol: "ws", | |
host: "localhost", | |
port: 64999, | |
clientPort: 64999, | |
}; | |
export default defineConfig({ | |
root: dirname(fileURLToPath(import.meta.url)), | |
plugins: [react()], | |
define: { | |
"process.env": JSON.stringify({ | |
SHOPIFY_API_KEY: process.env.SHOPIFY_API_KEY, | |
NODE_ENV: process.env.NODE_ENV, | |
}), | |
}, | |
resolve: { | |
preserveSymlinks: true, | |
}, | |
server: { | |
host: "localhost", | |
port: process.env.FRONTEND_PORT, | |
hmr: hmrConfig, | |
proxy: { | |
"^/(\\?.*)?$": proxyOptions, | |
"^/api(/|(\\?.*)?$)": proxyOptions, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment