JohnPremKumar / vite-plugin-favicons-inject

A Vite plugin for creating and injecting favicons during the application build!
MIT License
10 stars 3 forks source link

path.join flips // to \ in windows #6

Closed bradder555 closed 1 year ago

bradder555 commented 2 years ago

In windows, path.join("before","./","./","after") has the behavior of returning "before\after": image

Obviously creates issues when used for a URL on this line: https://github.com/JohnPremKumar/vite-plugin-favicons-inject/blob/18608ca22363a55de512f3fb847b4d8c311a6f30/src/index.js#L41

perhaps use new URL instead?

const fullUrl = new URL(path.join(path1, path2), baseUrl).toString();

https://javascript.plainenglish.io/how-to-safely-concatenate-url-with-node-js-f6527b623d5

I have a short-term workaround, in my vite.config.js file:

import { defineConfig } from 'vite'
import vitePluginFaviconsInject from 'vite-plugin-favicons-inject';

export default defineConfig({
  plugins: [
    vitePluginFaviconsInject(
      './src/assets/favicon.svg'
      )
  ],
  build: {
    sourcemap: true,
    outDir: "./dist",
    assetsDir: "assets"   
  },
  root: "./",
  base: "./"
});
JohnPremKumar commented 2 years ago

Thank you for the information.

Will look into it!

perwramdemark commented 1 year ago

Thanks this helped me! Had the same issue

gaetandezeiraud commented 1 year ago

I have the same issue.

gaetandezeiraud commented 1 year ago

Any news @JohnPremKumar ? Because the workaround proposed before is not possible for me.

JohnPremKumar commented 1 year ago

Will check and update the package soon.

gaetandezeiraud commented 1 year ago

config.path = opPath.replace('\\', ''); also work if you search a very quick fix.

JohnPremKumar commented 1 year ago

Thank you for sharing the suggestion. Will push an update today. Was busy with personal work.