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

The base property would be changed #4381

Closed
6 tasks done
fengxinming opened this issue Jul 24, 2021 · 5 comments
Closed
6 tasks done

The base property would be changed #4381

fengxinming opened this issue Jul 24, 2021 · 5 comments
Labels
p2-to-be-discussed Enhancement under consideration (priority)

Comments

@fengxinming
Copy link

Describe the bug

The base property would be changed when it got base on configResolved hook.

Reproduction

export default defineConfig({
  base: 'http://localhost:8000/',
  plugins: [
    {
      name: 'test',

      configResolved(config) {
        console.log(config.base);
      },
    }
  ]
});

it prints '/' not 'http://localhost:8000/'

System Info

MacBook Pro (Retina, 15-inch, Mid 2015)
macOS Mojave 10.14.6
[email protected]

Used Package Manager

npm

Logs

No response

Validations

@hyf0
Copy link
Contributor

hyf0 commented Aug 14, 2021

 const config = {
  base: 'http://localhost:8000/',
  plugins: [
    {
      name: 'test',
      config(config) {
        console.log(config.base); // => 'http://localhost:8000/',
      },
      configResolved(config) {
        console.log(config.base); // => '/'
      },
    }
  ]
  // ...
}

resolveBaseUrl remove the origin part of base.

// resolve public base url
const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger)

Then, overwrite base.
const resolved: ResolvedConfig = {
...config,
configFile: configFile ? normalizePath(configFile) : undefined,
configFileDependencies,
inlineConfig,
root: resolvedRoot,
base: BASE_URL,
resolve: resolveOptions,

It's hard to decide whether it is a bug? It does look confusing.

I personally don't consider it a bug and it should be mentioned in docs to avoid becoming an undefined behavior or split vite.config.js#base and resolved#base into two variable names.

@bluwy
Copy link
Member

bluwy commented Mar 13, 2022

This looks like a dev-only behaviour, but fixing would cause a breaking change given how long this behaviour had existed, and I'm not sure if it's correct either. My understanding is that it's / in dev mode because the full http://localhost:8000 doesn't make sense as your files would definitely reside based on the Vite dev server, instead of an arbitrary localhost url.

Re config and resolvedConfig, it looks expected to me that Vite does a final resolve of the base URL in resolved. Maybe the better solution overall is indeed documentation, but I'm not sure where this resides at.

@sapphi-red
Copy link
Member

Some slightly related conversations: #4274 (comment)

@sapphi-red sapphi-red added p2-to-be-discussed Enhancement under consideration (priority) and removed pending triage labels Jun 16, 2022
@ElMassimo
Copy link
Contributor

ElMassimo commented Dec 2, 2022

Don't want to increase the noise here, so I edited my previous comment.

In most cases, users that want to provide a full origin to base in development should use server.origin instead, which was added in:

@bluwy
Copy link
Member

bluwy commented Dec 10, 2022

We also discussed in the last meeting that this is intentional. Vite will resolve the base for it's internal use. You can use server.origin for other cases.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Dec 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

No branches or pull requests

5 participants