2

I have a Nuxt 3 application (3.0.0-rc.13) generating a static website, and have to deploy to two locations:

  1. Firebase hosting
  2. Amazon S3 bucket

Hosting on Firebase needs a baseUrl of /, and Amazon needs a different baseUrl (/2223/). This can be configured in nuxt config, however I cannot find an cli option to specify which config file to use.

I have tried these, but they just pick the default nuxt.config.ts.

nuxt generate -c nuxt.config.amazon.ts
nuxt generate --config-file nuxt.config.amazon.ts

I found this issue that added support to it for Nuxt 2, but I cannot find anything about it for Nuxt 3. Am I missing something or is it just not supported at all?

EmJee
  • 143
  • 9
  • 1
    You could use environment variables with an `.env` file, still the best way to handle such use-case. – kissu Nov 08 '22 at 16:16
  • 1
    Here is an exhaustive answer on how to work with those: https://stackoverflow.com/a/67705541/8816585 – kissu Nov 08 '22 at 16:18

1 Answers1

1

Thanks for the solution @kissu If anyone faces the same problem, here is how I implemented it:

package.json scripts:

"generate": "cross-env DEPLOY_TARGET=default nuxt generate",
"generate:amazon": "cross-env DEPLOY_TARGET=amazon nuxt generate",

nuxt.config.ts

const getBaseUrl = () => {
  const environment = process.env.DEPLOY_TARGET;

  switch (environment) {
    case "amazon":
      return "/2223/";
    default:
      return "/";
  }
};

export default defineNuxtConfig({
  app: {
    baseURL: getBaseUrl(),
  },
});
EmJee
  • 143
  • 9
  • I recommend doing that the other way around actually (no need for conditions). But you are to decide at the end. – kissu Nov 08 '22 at 16:58