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

Support optional public base path configuration #8540

Closed
4 tasks done
marrypen opened this issue Jun 11, 2022 · 6 comments
Closed
4 tasks done

Support optional public base path configuration #8540

marrypen opened this issue Jun 11, 2022 · 6 comments

Comments

@marrypen
Copy link

Clear and concise description of the problem

Based on the document,

JS-imported asset URLs, CSS url() references, and asset references in your .html files are all automatically adjusted to respect this option during build.

Vite handles all asset references automatically which means inject base path for all resources in .html files. I'm facing one situation which is that, in index.html some resource references are provided by other microservices but in same origin, these resource should not respect the base public path config. I didn't find a solution to solve this problem.

Suggested solution

Maybe base can provide a exclusion config or there is a flag we can use to mark these resources to not respect the base public path config.

Alternative

No response

Additional context

No response

Validations

@patak-dev
Copy link
Member

Maybe the base param could accept a function to cover your use case. But I'm unsure if the extra complexity is justified. You could achieve this in user land with a plugin using transformIndexHtml.

Also you can check out a related the proposal at

@marrypen
Copy link
Author

Maybe the base param could accept a function to cover your use case. But I'm unsure if the extra complexity is justified. You could achieve this in user land with a plugin using transformIndexHtml.

Also you can check out a related the proposal at

The transformIndexHtml hook is working, problem currently solved. But I have to hark code those resources in two different places which makes it difficult to maintenance in the future. Waiting for a more convenient solution.

@sapphi-red
Copy link
Member

But I have to hark code those resources in two different places

One of the place is transformIndexHtml hook, what is the another place?

@marrypen
Copy link
Author

marrypen commented Jun 17, 2022

First the reference should be placed in index.html, then in vite.config.ts I have to use transformIndexHtml to remove the base config path for those resource references.

@sapphi-red
Copy link
Member

I see. How about doing it like this? (stackblitz)

import { defineConfig } from 'vite';

export default defineConfig({
  base: '/foo/',
  plugins: [
    {
      name: 'inject',
      transformIndexHtml() {
        return [
          {
            tag: 'script',
            attrs: { type: 'module', src: '/external.js', defer: true },
          },
        ];
      },
    },
  ],
});

@sapphi-red
Copy link
Member

Closing due to lack of response.
Also I believe this is resolved by #8762.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants