GithubHelp home page GithubHelp logo

Comments (3)

credred avatar credred commented on September 2, 2024 1

Thank you very much for taking the time to solve this problem. Have a nice weekend. 😀

from vite-plugin-lib-inject-css.

emosheeep avatar emosheeep commented on September 2, 2024

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🙏.

from vite-plugin-lib-inject-css.

emosheeep avatar emosheeep commented on September 2, 2024

Reason

I dive deep into the source code of Vite and found that the common css file you referenced will be transform into a pureCssChunk like:

// common.Bkwfiy39.js
import "../assets/common.css";

And then you'll get import "./common.Bkwfiy39.js"; in the origin chunk

import { test as i } from "../common.js";
import "./common.Bkwfiy39.js"; // It's a common chunk.

But after the internal cssPostPlugin hook generateBundle was executed, all of the pureCssChunks imports were replaced with empty css comment.

import { test as i } from "../common.js";
/* empty css                */

But! Vite will pass the removed chunk's viteMetaData to the dependent chunk, which is done in generateChunk, here's detail:

// 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;
});

Conclusion

Our plugin finish code injection at renderChunk hook which is executed before generateChunk, that's what happened to you. Maybe I should consider how to complete it in generateChunk hook. 🤔🤔

from vite-plugin-lib-inject-css.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.