aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
653 stars 58 forks source link

Update serializeDefine implementation from upstream vite #193

Closed vasiliicuhar closed 5 months ago

vasiliicuhar commented 5 months ago

This PR updates serializeDefine to latest version from vite. It fixes compilation errors when define contains string values.

[vite:define] Transform failed with 1 error:
error: Invalid define value (must be an entity name or valid JSON syntax)

For some unknown reasons it's not working only in combination with @vitejs/plugin-react, however, the issue is with (${val}) syntax, that esbuild doesn't accept.

Environment

node@18.18.2
vite@^5.2.12
vite-plugin-web-extension@4.1.3
@vitejs/plugin-react@^4.3.0

Sample config

export default defineConfig({
  define: {
    "process.env.REACT_APP_BASEURL": '""'
  },
  plugins: [
    react(),
    webExtension({
      manifest: generateManifest,
    }),
  ]
})
aklinker1 commented 5 months ago

Interesting, must have broken on some new version of vite? Last I checked, you still had to define string constants like so '"some text"', and JSON.stringify did that for you...

That and skipping the final comma seen to be the only changes?