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)
- Segmentation fault when building sveltekit library with dependency using FFI HOT 1
- Dynamic imports doesn't work after i upgraded to Vite 5.3.1 HOT 9
- VITE_ASSET and `rollup-replace` plugin
- 5.3.0: Proxy should not rewrite the Origin header for non WS requests HOT 1
- Document not defined in worker import HOT 2
- what i cant understand is build.rollupOptions.cache means like production env build cache? but when i open that ,i cant perceive anything changed
- 字体图标无法正确加载 HOT 1
- __vite__mapDeps optimization breaks configuration depending on Vite bundling HOT 1
- Suppress `dynamic import cannot be analyzed by Vite` warning for dynamic imports with /* webpackIgnore: true */ HOT 1
- Error `Unexpected token '{'` after upgrade from [email protected] HOT 2
- Typings incorrect for CommonServerOptions `https`, should be `| boolean` HOT 1
- Support `resolve.alias` per environment in Environments API HOT 6
- Invalid relative path in index.html when building with base option empty in Windows HOT 3
- tsc --noEmit does not detect issues in react-ts template HOT 2
- Dynamic require doesn't work in dev mode HOT 1
- `lightningcss` is dynamically imported but not bundled or installed HOT 3
- Multiple pass for the build
- Deyloy productions: proxy not working
- Update version of postcss-load-config
- Unable to completely disable Rollup's tree shaking HOT 2
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.