Giter VIP home page Giter VIP logo

Comments (3)

bluwy avatar bluwy commented on July 4, 2024

I don't quite understand the feature request:

  1. What are you generating from the source file?
  2. Are you using a tool or compiler to generate it?
  3. What about using a Vite plugin with the transform() hook to transform the code so you don't need a separate file?
  4. What kind of API are you thinking that Vite could expose?

Otherwise this seems fine to be implemented externally as a Vite plugin.

from vite.

orwithout avatar orwithout commented on July 4, 2024

I have indeed written an external plugin to meet the needs of dynamically generating files. This is very simple, but the extended capabilities are exciting to me (very cost-effective).

I currently use "source file" to dynamically generate a list of files of a specified file type in a specified directory (for example, /src/lib/*_storage_io.js). (Configure vite.config.js to call a js program at each compilation, this js program will scan the /src/lib/ directory, and then create a new file /src/storage_list.json to output the scanned information to it)

If you consider the potential use, this may encourage another style of programming paradigm. A simple example: suppose I want to design landing pages for 1,000 products. Using the method here, I will be able to hard-code the url of each product's image resource and dynamically generate 1,000 html without any js code. Is this very different from pages that must be implemented using javascript?

Assuming that Vite has this feature built in, I expect it to globally recognize specific file suffixes in the project, such as .source.js, and then automatically execute the code in it at compile time.
(Or consider providing another suffix: .mustache.js so that during compilation, the code in it can be directly replaced with a template to generate a .js with the same name in the same path)

Compared to the transform() method, this will do more things in the compiler, and the generated target code will be more concise and diverse.

If Vite has this method built in, I think it would be very cool. Of course, it is also easy for users to implement it themselves using external plug-ins.

from vite.

bluwy avatar bluwy commented on July 4, 2024

If I understand correctly, you want an easy way to "for these source files, compile with this js program, put them in that directory"? Vite's and Rollup's transform flow intentionally pushes against generating files like this, since it can be achieved with virtual modules.

I understand though that generating the files explicitly in the fs has its benefits too, but at the moment, I don't think it's something Vite would support first-class. However, it may be easier to test your idea with the community now if you can share a Vite plugin that implements this feature generically. I'll close this for now.

from vite.

Related Issues (20)

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.