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

Missing CSS in production because indexHtmlPath isn't correctly stripped #18

Closed
cewald opened this issue Nov 3, 2022 · 4 comments
Closed

Comments

@cewald
Copy link

cewald commented Nov 3, 2022

I'm having trouble with the production build when the public-base-path of vite isn't the default one. The style-tag nor the CSS file (if injectAsStyleTag is false) is injected. It works fine if I use the default base config in my vite.config.js.

I had a look at the code and saw that there is a replace of the path for the indexHtmlPath variable which on default replaces the trailing / of the index.html path, but won't replace it properly if the base isn't just /.
https://github.com/feat-agency/vite-plugin-webfont-dl/blob/master/src/index.ts#L285

The generateBundle method then won't find the index.html file in the bundle array:
https://github.com/feat-agency/vite-plugin-webfont-dl/blob/master/src/index.ts#L312

Any experience with that – shouldn't this be considered?

@cewald cewald changed the title indexHtmlPath isn't correct when base is not / Missing CSS in production because indexHtmlPath isn't correctly stripped Nov 3, 2022
@cewald
Copy link
Author

cewald commented Nov 3, 2022

This is my vite.config.ts:

import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import webfontDownload from 'vite-plugin-webfont-dl'
import svgLoader from 'vite-svg-loader'
import Icons from 'unplugin-icons/vite'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/cv/',
  plugins: [
    vue(),
    vueJsx(),
    svgLoader(),
    Icons({}),
    webfontDownload(
      [
        'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap',
        'https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap'
      ],
      {}
    )
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    port: 3000
  }
})

And this it the index.html production output:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/cv/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>...</title>
    <script type="module" crossorigin src="/cv/assets/index.27d05be5.js"></script>
    <link rel="stylesheet" href="/cv/assets/index.23033122.css">
  </head>
  <body>
    <div id="app"></div>
    
  </body>
</html>

@0xb4lint
Copy link
Member

0xb4lint commented Nov 3, 2022

Thank @cewald for raising this issue!

I've just created a fix and released 3.4.1-beta.0.
Could you please try it and get back to me?

@cewald
Copy link
Author

cewald commented Nov 3, 2022

I tested it and it works in dev and production mode, using injectAsStyleTag and without.
That was quick – thank you!

@0xb4lint
Copy link
Member

0xb4lint commented Nov 3, 2022

Thank you!

I've just published v3.4.1.

@0xb4lint 0xb4lint closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants