Comments (3)
I don't quite understand the feature request:
- What are you generating from the source file?
- Are you using a tool or compiler to generate it?
- What about using a Vite plugin with the
transform()
hook to transform the code so you don't need a separate file? - 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.
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.
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)
- Create Vite - Remix - "remix command not found" HOT 3
- Not detected recurrence in scss code (@mixin calling itself) leading to build failure HOT 5
- `vite build` can fail when resolving root `tsconfig.json` extends HOT 2
- Add a plugin hook like 'insertTagsToHtml' to support dynamic public path in the index.html
- The output code execution results of the ts code compiled by vite and the code compiled by tsc are inconsistent HOT 4
- React component in node_modules doesn't fast-refresh HOT 2
- The results of code compiled with vite and code compiled directly with esbuild are inconsistent,Decorators related issues HOT 9
- Dev server will return index when file not exists HOT 3
- Importing .vue file in WebWorker causes error when building. HOT 2
- `Sourcemap for ... points to missing source files` for `@import` with sass modern api HOT 1
- Relative CSS asset import does not work with root config set HOT 1
- Write asset string directly into source file instead of an imported file HOT 8
- vite build hangs with multiple scss input files when using 'modern-compiler' HOT 1
- Upgrade to chokidar v4 HOT 2
- Error: [plugin ] Cannot convert undefined or null to object when running Qwik-TS TypeScript in Vite HOT 3
- Problem with resolving SASS files when the build files are in a subfolder HOT 2
- Windows + yarn pnp: [vite] Get yarn cache dir error: spawnSync C:\Windows\system32\cmd.exe ENOENT HOT 1
- Uncaught ReferenceError: __DEFINES__ is not defined at env.ts:17:17 HOT 1
- Referenced Project May Not Disable Emit HOT 1
- SSR transform sets `map.sources` paths incorrectly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vite.