-
To prepare my app to move from development to production, I wanted to use a conditional Vite configuration. The basic configuration import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
plugins: [vue()],
}); When changing the content of this file to export a function, the serve/build fails: import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
// configuration common to serve and build stages
const baseConfig = {
plugins: [vue()],
};
// specific settings
if (command === "serve") {
return {
...baseConfig,
define: {
__BACK_WS_URI__: "ws://localhost:8080/ws",
__BACK_HTTP_SPA__: "http://localhost:8080/spa",
},
};
} else {
return {
...baseConfig,
define: {
__BACK_WS_URI__: "XXX",
__BACK_HTTP_SPA__: "YYY",
},
};
}
}); The error is
What is wrong with this configuration? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Having the same issue after using |
Beta Was this translation helpful? Give feedback.
-
@wsw70 , I found a way to fix it. define: {
__BACK_WS_URI__: "'ws://localhost:8080/ws'",
__BACK_HTTP_SPA__: "'http://localhost:8080/spa'",
}, |
Beta Was this translation helpful? Give feedback.
@wsw70 , I found a way to fix it.
You need to add quotes, because
define
expects expressions, like this: