nuxt / bridge

🌉 Experience Nuxt 3 features on existing Nuxt 2 projects
MIT License
273 stars 29 forks source link

Vite entry-legacy.js is not ES5 compatible #340

Open IlyaSemenov opened 2 years ago

IlyaSemenov commented 2 years ago

Environment

Reproduction

Create empty project with this nuxt.config.js:

import { defineNuxtConfig } from '@nuxt/bridge'
import legacy from '@vitejs/plugin-legacy'

export default defineNuxtConfig({
  bridge: {
    vite: true,
  },
  hooks: {
    'vite:extendConfig': config => {
      config.plugins.forEach((plugin, i) => {
        if (Array.isArray(plugin) && plugin[0].name === 'vite:legacy-config') {
          config.plugins[i] = legacy({
            targets: ['ie 9'],
          })
        }
      })
    },
  },
})

Then run nuxi build.

.output/public/_nuxt/entry-legacy.c81f3a42.js will include code that does not run in IE 9:

var appConfig = window?.__NUXT__?.config.app || {}

Describe the bug

nuxi build generates ES5-incompatible javascript even if @vitejs/plugin-legacy is configured with IE 9 target. The plugin itself works fine, the problem is apparently that Nuxt-injected code is not processed with that plugin.

Additional context

No response

Logs

No response

IlyaSemenov commented 2 years ago

See https://github.com/nuxt/bridge/discussions/341 as well.

IlyaSemenov commented 1 year ago

In @nuxt/bridge-edge@3.0.0-27778503.de9e5c2, the entry point syntax is ES5 compatible, however it won't work in legacy browsers due to:

globalThis.__publicAssetsURL = function(id) { return joinURL(publicBase, id || "") }
image