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

top-level external option for setting external modules for both dev and build #12711

Closed
4 tasks done
hronro opened this issue Apr 3, 2023 · 4 comments
Closed
4 tasks done

Comments

@hronro
Copy link
Contributor

hronro commented Apr 3, 2023

Description

There is an option called build.rollupOptions.external, but it is only for vite build. Currently, there is no way to set external modules both for dev and build.

Suggested solution

Add a top-level external option, which set external modules for both dev and build (including deps optimizer as well). And the default of build.rollupOptions.external should be changed to be the same as the top-level external option.

Alternative

No response

Additional context

A minimal example that needs to set external modules for both dev and build, is to use a javascript library (ESM format) hosted on CDN(or any other server), just like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Vite App</title>
    <script type="importmap">
      {
        "imports": {
          "lodash": "https://unpkg.com/lodash-es@4.17.21/lodash.js"
        }
      }
    </script>
  </head>
  <body>
    <script type="module">
      import { random } from 'lodash'
      console.log('random number', random(1, 5))
    </script>
  </body>
</html>

Validations

@sapphi-red
Copy link
Member

Currently, there is no way to set external modules both for dev and build.

I guess you can use a plugin to do this (#12751 (comment)).

@hronro
Copy link
Contributor Author

hronro commented Apr 7, 2023

@sapphi-red

Cool, I'll try that, but is it documented in vitejs.dev?

BTW, writing a plugin to do such a thing makes me feel weird, I still think it worse to have a standalone option.

@bluwy
Copy link
Member

bluwy commented Apr 7, 2023

This could be an option to standardize externalizing things, I've put some related issues regarding this in the team board for discussion. Related: #11854 (comment)

@bluwy
Copy link
Member

bluwy commented May 14, 2023

I realized this is requesting for the same feature as #6582. Closing this in favour of that as it's older, and has a few reactions on the issue. I've left an update of the status of the feature at #6582 (comment)

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants