DEV Community

Bill Kervaski
Bill Kervaski

Posted on

Vite v4 to v5 global replacement

Hello!

We're migrating from v4 to v5 and want to use defineConfig for global repalcement and conditional imports:


define: {
        _VERSION_: JSON.stringify(process.env.npm_package_version),
        _PLATFORM_: JSON.stringify('Desktop'),
        _ENGINE_: JSON.stringify('electron'),
},

Enter fullscreen mode Exit fullscreen mode

However, we can't seem to use global repalcements for dynamic imports:

import Tone from './tone/_ENGINE_.js'
import Push from './push/_ENGINE_.js'
Enter fullscreen mode Exit fullscreen mode

We end up with the following error:

Could not resolve "./push/_ENGINE_.js" from "src/js/main.js"
Enter fullscreen mode Exit fullscreen mode

Looking for suggestions, thanks for any help :D

Top comments (1)

Collapse
 
2b9500ab99ef7 profile image
Arkadiy Mel

You can try using the resolve.alias (vitejs.dev/config/shared-options.h...) option for this, but I think all the paths would need to be specified manually.

If this is an issue, you could try supplying resolve.alias.customResolver (github.com/rollup/plugins/tree/mas...) and replacing the defines there.