Rollup: Create a generic main.js that imports built JS file - vite

I want to access a consistent script from HTML that always returns the latest built assets of rollup via vite. I see that one can gain awareness of the file name via manifest.json and but I want to generate a JS file like
import "_main-03d3g4.js"
that I can point a script at and that dynamically updates every build. This is similar to how an index file gets an updated script src in rollup-plugin-generate-html-template

Related

Bundling and distributing json file within extension to then read it

I'm looking to add omnibox suggestions using flexsearch index which may be exported as files. I saw api for downloading a file, but I'd rather not have to host the index (also I dont want the hustle of copying data to non-user reachable environment). Is there some manifest field to require that json be included in extension bundle and api for reading it?
I've tried simply importing json file from within js and that works. I believe what that means is that exported index would be stored in dist/js bundle.

How to write inside a file at specific position using nodejs?

I am building an interactive CLI project generator and I want to have a similar feature like angular CLI have.
Although I am working on to generate folders and files but I am not sure that how can I write inside a file at a specific position.
Suppose, when we generate a component using angular cli, it registers the component inside our modules file. So how can I write inside a file at specific location? Say if I want to include a require tag in node inside a file how would I do it? How would I know at what position the imports are ending and at what position do I include it?
You could create simple CLI using REPL module in Node.js
https://nodejs.org/dist/latest-v10.x/docs/api/repl.html
For creating folders/files you could use fs module
https://nodejs.org/dist/latest-v10.x/docs/api/fs.html
For running external commands (like git init), you could use child_process module (exec method)
https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_child_process_exec_command_options_callback

TypeScript lint files and folders based on allowing what modules can and cannot be imported

Let's say I'm starting a TypeScript project with a models, views, and controllers. I am interested in adding linting at the file and folder level that states what the rules are for a given folder and file type.
For instance a view (any of the TypeScript files within the views folder) should never import anything from the models folder.
Another example would be that any file within the routes folder should be forced to import express.
Another example is that all files within components should always require react.
Here are the relationships I am looking for:
should always import
should never import
should only import
Is this possible within the TypeScript or even Node.js ecosystem? Are there any projects that do this?
I'd also like if there was a way to force what type of variable is returned from all the files in a folder, for example all files within components should return react components. All files within json folder should return json.

Node getting confused between same names static files present in different folder

I have the following code in my app.js file,
app.use(express.static('views/app1/dist'));
app.use(express.static('views/app2/dist'));
but here I have same named JS files in both folder, they are designed to represent respective HTML file present in the same folder.
The problem here is that even though I am routing to "app2" HTML file, the "app1" JS files are getting called.
Need help in making NODE understand which folder files to execute.
The code screams that you are using NODE.JS with EXPRESS, and Angular 4, so following are the tips for you:
Avoid having files with the same name, it increases the computation load on the server,
Instead of using ng build, use ng build --prod, this will create unique named files, so no clashing.

Combine and minify js file using nodejs dynamically

I am new to nodejs and grunt.
I was going through the less-middleware and was very impressed with the way it automatically creates the css files. I now want the same for js files also. Let me briefly explain -
User makes a request to site.min.js
The routes automatically captures the particular request.
Nodejs creates a new combined and minified js file based on the input parameters if the file is not already present.
Return the combined file.
I feel grunt is not the right way to go about it since every time the js files are updated I will have to commit new version of the min file to the repo. I want some dynamic mechanism of creating the minified version.
Also not that i am trying to deploy my code on heroku.
Grunt will compile your js files during the build. I'm not aware of a runtime pull-and-minify for javascript.

Resources