IlyaSemenov / nuxt-vite-legacy

Nuxt.js legacy build
MIT License
46 stars 4 forks source link

load all js file in nuxt3 #15

Closed InvincibleJun closed 2 months ago

InvincibleJun commented 2 months ago

Hello, Author. I use nuxt-vite-legacy lib in my init nuxt3 project.we will use it in chrome 58.

I configured it as follows.

nuxt.config.js

export default defineNuxtConfig({
  devtools: { enabled: true },

  modules: [
    'nuxt-vite-legacy',
  ],

  legacy: {
    targets: ['chrome >= 49', 'firefox >= 64', 'safari >= 10.1', 'edge >= 16'],
    additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
    modernPolyfills: [
      'es.global-this',
      'es.object.from-entries',
      'es.array.flat-map',
      'es.array.to-sorted',
      'es.array.flat',
      'web.queue-microtask',
    ],
  },
});

package.json

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev --host",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "devDependencies": {
    "nuxt": "3.13.1",
    "nuxt-vite-legacy": "^1.2.0",
    "terser": "^5.32.0",
    "vue": "^3.5.3"
  },
  "overrides": {
    "vue": "latest"
  }
}
<template>
  <div>
    <!-- <NuxtRouteAnnouncer /> -->
    <NuxtWelcome @click="handleClick" />
  </div>
</template>
<script setup lang="ts">
const handleClick = () => {
  alert(1);
}
</script>

Then open chrome128 working fine, click alert 1 as ok. but it load all javascript file.

image

Then open chrome63 working bad, click it not alert .And load all javascript file. image

I guess: in client render project, vite legcy plugin will inject some inline script into html file.Howerer, in server render will not inject some line script.

So, I need your help. Thanks

IlyaSemenov commented 2 months ago

Please check your code with Nuxt 3.8. If it works, then the module must be updated to support Nuxt 3.13.

The module uses regexps to fiddle with output HTML: https://github.com/IlyaSemenov/nuxt-vite-legacy/blob/c98e1dbf9f00cfce9990d6ca753edc45a6f0e0ca/src/runtime/server-plugin.ts#L7-L12

This was only tailored to Nuxt 3.4—3.8 output.

InvincibleJun commented 2 months ago

Thanks for reply.

IlyaSemenov commented 2 months ago

So did it work? Why'd you close the issue?

IlyaSemenov commented 1 month ago

FWIW, I updated regexps to work with Nuxt 3.13 and @vitejs/plugin-legacy 5.4.