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

vite build fails when using build.rollupOptions.external together with <link rel="stylesheet"> #6931

Closed
7 tasks done
eemeli opened this issue Feb 15, 2022 · 2 comments
Closed
7 tasks done

Comments

@eemeli
Copy link

eemeli commented Feb 15, 2022

Describe the bug

If the build.rollupOptions.external config option includes a CSS file as a path, a <link rel="stylesheet"> tag matching that path is incorrectly removed from the index.html file and inserted into the JS file, breaking the result as it's then left there as import "...css" by Rollup due to the external config. This only affects the production build, as in dev mode the <link> is left intact and works as expected.

In the code, this looks like the culprit:

const isExcludedUrl = (url: string) =>
url.startsWith('#') ||
isExternalUrl(url) ||
isDataUrl(url) ||
checkPublicFile(url, config)

if (!isExcludedUrl(url)) {
if (node.tag === 'link' && isCSSRequest(url)) {
// CSS references, convert to import
js += `\nimport ${JSON.stringify(url)}`
shouldRemove = true
} else {
assetUrls.push(p)
}

I'm willing to file a PR fixing this, if it's okay to introduce a dependency in buildHtmlPlugin() on the value of the build.rollupOptions.external config option?

Reproduction

https://gist.github.com/eemeli/97b34dc72c886dffa25168699fe81e79

System Info

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 73.81 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.4.0 - /opt/homebrew/bin/node
    Yarn: 1.22.11 - /opt/homebrew/bin/yarn
    npm: 8.3.1 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 98.0.4758.80
    Firefox: 96.0.3
    Safari: 15.2
  npmPackages:
    vite: ^2.8.0 => 2.8.2

Used Package Manager

npm

Logs

No response

Validations

@poyoho
Copy link
Member

poyoho commented May 10, 2022

now It seems to call warning for this case even no setting build.rollupOptions.external. So can I close this issues?

@eemeli
Copy link
Author

eemeli commented May 10, 2022

Sure. We ended up not using Vite after all, so I can't easily test the current behaviour.

@poyoho poyoho closed this as completed May 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2022
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

2 participants