Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @vitejs/plugin-legacy #309

Open
khalwat opened this issue Jun 4, 2021 · 6 comments
Open

Support @vitejs/plugin-legacy #309

khalwat opened this issue Jun 4, 2021 · 6 comments
Labels
build Related to the build system enhancement New feature or request stale

Comments

@khalwat
Copy link

khalwat commented Jun 4, 2021

I'm attempting to use VitePress with the Vite plugin legacy-plugin, but on build I receive this error:

build error:
 Error: @vitejs/plugin-legacy rollupOptions.output.entryFileNames and rollupOptions.output.chunkFileNames does not support the function format.
    at getLegacyOutputFileName (/app/node_modules/@vitejs/plugin-legacy/index.js:182:17)

Here's my vite.config.js:

import { defineConfig } from 'vite'
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        legacy({
           targets: ['defaults', 'not IE 11']
         }),
        ],
  server: {
    host: '0.0.0.0',
    port: 3002,
    strictPort: true,
  }
});

Seems like building a legacy bundle for documentation would be a desirable thing, so that the broadest possible clients can read them?

@khalwat khalwat added the bug: pending triage Maybe a bug, waiting for confirmation label Jun 4, 2021
@khalwat
Copy link
Author

khalwat commented Jul 11, 2021

Should be solved by: vitejs/vite#4122

ref: vitejs/vite#3636

@khalwat
Copy link
Author

khalwat commented Jul 15, 2021

This is unfortunately not fully resolved by the above as I thought it might be.

Doing a build of the docs with the Legacy plugin included now results in:

⠴ building client + server bundles...[vite:dynamic-import-polyfill] Vite's dynamic import polyfill is enabled but was never imported. This should only happen when using custom non-html rollup inputs. Make sure to add `import "vite/dynamic-import-polyfill"` as the first statement in your custom entry.
✖ building client + server bundles...
build error:
 Error: Vite's dynamic import polyfill is enabled but was never imported. This should only happen when using custom non-html rollup inputs. Make sure to add `import "vite/dynamic-import-polyfill"` as the first statement in your custom entry.
    at Object.renderDynamicImport (/app/node_modules/vite/dist/node/chunks/dep-11db14da.js:29320:23)
    at PluginDriver.runHookSync (/app/node_modules/rollup/dist/shared/rollup.js:20178:25)
    at PluginDriver.hookFirstSync (/app/node_modules/rollup/dist/shared/rollup.js:20060:33)
    at ImportExpression.getDynamicImportMechanismAndHelper (/app/node_modules/rollup/dist/shared/rollup.js:8115:40)
    at ImportExpression.setExternalResolution (/app/node_modules/rollup/dist/shared/rollup.js:8103:55)
    at Chunk.prepareDynamicImportsAndImportMetas (/app/node_modules/rollup/dist/shared/rollup.js:12878:34)
    at Chunk.preRender (/app/node_modules/rollup/dist/shared/rollup.js:12323:14)
    at Bundle.prerenderChunks (/app/node_modules/rollup/dist/shared/rollup.js:13644:19)
    at Bundle.generate (/app/node_modules/rollup/dist/shared/rollup.js:13509:18)
    at async handleGenerateWrite (/app/node_modules/rollup/dist/shared/rollup.js:20969:23) {
  code: 'PLUGIN_ERROR',
  plugin: 'vite:dynamic-import-polyfill',
  hook: 'renderDynamicImport'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ docs:build: `npm run docs:fix && npm run docs:lint && vitepress build docs`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ docs:build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-07-15T03_36_42_350Z-debug.log

@khalwat khalwat reopened this Jul 15, 2021
@kiaking kiaking added enhancement New feature or request build Related to the build system and removed bug: pending triage Maybe a bug, waiting for confirmation labels May 24, 2022
@brc-dd brc-dd changed the title legacy-plugin errors when used with VitePress Support @vitejs/plugin-legacy Jul 3, 2022
@Topthinking
Copy link

When will it be settled

@brc-dd
Copy link
Member

brc-dd commented Jul 3, 2022

If anyone is trying to fix this, here is the cause: https://github.com/vuejs/vitepress/blob/baf8083e668ce50a9d26d9398609e196237ebc95/src/node/build/bundle.ts. Currently we assume build output to be of type RollupOutput always, but in case we add legacy plugin, the output is of type RollupOutput[].

@Topthinking
Copy link

If anyone is trying to fix this, here is the cause: https://github.com/vuejs/vitepress/blob/baf8083e668ce50a9d26d9398609e196237ebc95/src/node/build/bundle.ts. Currently we assume build output to be of type RollupOutput always, but in case we add legacy plugin, the output is of type RollupOutput[].

Can I add a judgment on arrays RollupOutput[].

@brc-dd brc-dd added upstream Related to the dependencies and removed upstream Related to the dependencies labels Jul 4, 2023
@brc-dd
Copy link
Member

brc-dd commented Jul 4, 2023

If anyone is trying to fix this, here is the cause: https://github.com/vuejs/vitepress/blob/baf8083e668ce50a9d26d9398609e196237ebc95/src/node/build/bundle.ts. Currently we assume build output to be of type RollupOutput always, but in case we add legacy plugin, the output is of type RollupOutput[].

Okay so this is a bit more complex than that. Even if we handle that multiple targets (array thing), we still would need a lot of refactoring. There are a bunch of places where we are manually emitting assets having exports, and script tags with type module. These all won't work in older browsers. It would be a bit hard to do that. In the meantime you can use build.target + polyfill.io to slightly improve coverage.

@github-actions github-actions bot added the stale label Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Related to the build system enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

4 participants