Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to set subdomain #240

Closed
MordiSacks opened this issue Aug 28, 2023 · 4 comments
Closed

add option to set subdomain #240

MordiSacks opened this issue Aug 28, 2023 · 4 comments
Assignees

Comments

@MordiSacks
Copy link

I have multiple vite configurations for different parts of my app.
this parts are seperated by subdomain e.g.
example.com
mng.example.com
app.example.com

when I run dev, it gives me the APP_URL value, it would be nice if the configuration would have an option to set a prefix or a custom function even
like this

export default defineConfig({
    plugins: [
        laravel({
            url_prefix: 'mng.', // as prefix
            url: url => `mng.${url}`, // as function
            buildDirectory: 'build/mng',
            input: ['resources/builds/mng/js/app.js'],
            refresh: true,
        }),
    ]
});
@jessarcher
Copy link
Member

Hi @MordiSacks,

The APP_URL environment variable is only used for the console output to remind developers that the Laravel dev server URL differs from the Vite dev server URL that is output above. I'm not sure it's worth adding extra configuration to customise this.

You can, however, modify the APP_URL environment variable when running the dev server, like this:

APP_URL=http://mng.example.com npm run dev

You could add this to the scripts section of your package.json:

  "scripts": {
    "dev": "APP_URL=http://mng.example.com vite",
    // ...
  }

@MordiSacks
Copy link
Author

@jessarcher Thank you for your answer.

My envs usually look like this

APP_DOMAIN=example.test
APP_URL=https://${APP_DOMAIN}

I find this easy as I use the domain variable alot

Would this work (as not sure when dotenv lib is engaged)

  "scripts": {
    "dev": "APP_URL=https://mng.${APP_DOMAIN} vite",
    // ...
  }

@jessarcher
Copy link
Member

I don't think that would work, as the variables from your .env file wouldn't be available to read (only set) at that point.

You could set APP_URL above the defineConfig function in your vite.config.js file, though:

import { loadEnv } from 'vite'

const env = loadEnv('development', process.cwd(), ['APP_DOMAIN'])
process.env.APP_URL = `https://mng.${env.APP_DOMAIN}`

@MordiSacks
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants