-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Code injection failed when multiple entries are importing a same style file. #18
Comments
Seems a little strange…but I'm too busy to work on this now. I’ll appreciate it if there’s anyone who can open a pull request🙏. |
ReasonI dive deep into the source code of Vite and found that the common css file you referenced will be transform into a // common.Bkwfiy39.js
import "../assets/common.css"; And then you'll get import { test as i } from "../common.js";
import "./common.Bkwfiy39.js"; // It's a common chunk. But after the internal import { test as i } from "../common.js";
/* empty css */ But! Vite will pass the removed chunk's // remove pure css chunk from other chunk's imports,
// and also register the emitted CSS files under the importer
// chunks instead.
chunk.imports = chunk.imports.filter((file) => {
if (pureCssChunkNames.includes(file)) {
const { importedCss, importedAssets } = bundle[file].viteMetadata;
importedCss.forEach((file) => chunk.viteMetadata.importedCss.add(file));
importedAssets.forEach((file) => chunk.viteMetadata.importedAssets.add(file));
return false;
}
return true;
}); ConclusionOur plugin finish code injection at |
Thank you very much for taking the time to solve this problem. Have a nice weekend. 😀 |
import './test.css' became
/** empty css */`I noticed that empty css is replaced by vite: css post
Here is the example
https://stackblitz.com/edit/vitejs-vite-7eeqqk?file=vite.config.ts&view=editor
The text was updated successfully, but these errors were encountered: