How to prevent creating a nested output directory in vite.js - javascript

For my vite app, I'm looking to have multiple entry points. In this case, I moved my index.html into src/main. After building, I noticed that there are nested directories in my dist folder which is not what I wanted.
I've been reading the rollup docs to find the correct option to prevent this but no luck. Any ideas?

I had the same problem as you and after hours of searching this is how I solved it:
Create js file (build.js - or whatever name you want)
In this build.js file with some help from nodejs file system module(fs) you can modify structure of dist folder as you want.
Finally, modify package.json file to run build.js file after vite build command, for example: "build": "vue-tsc --noEmit && vite build --mode=production && node PATH_TO_YOUR_BUILD_JS_FILE"

Related

How to compile a folder with multiple files JS format, node_modules, package.json to an executable

Good evening, I would like to know if there's a way to compile what I asked in the title to an executable. I've tried in the past using the node library /nexe with success, but the exe would work only inside the root folder with all its components. If you try to run it outside the folder it won't work. I've tried pkg but without success as it would crash when opening. I've tried Dino but same result. If there's something I'm missing let me know.
The root folder structure is pretty simple and contains the following.
node_modules
package.json
package-lock.json
folder with JS files that are connected to main.js
main.js

Deploying a NestJs project on a single board computer (Raspberry or similar)

even if it seems a simple task I'm having some trouble finding a solution. I know that with Nest CLI I can use the command "nest build" in order to create a dist folder that contains the production files of my project.
The problem is when I move the folder on my Raspberry and i try to run the project with the command "node dist/main" following NestJs instructions. Nothing starts because node says that it cannot find #nestjs/core and other modules.
I did't find nothing clear in the official guide about deploying the app, so my question is: what do I need to move onto my rasperry in addition to dist folder? Do I need to reinstall all node_modules folder or it's possible to have a running project without have to reinstall 800Mb of modules?
Yes you need to run yarn or npm install on your production environment, as your dist folder only contains your own code.
Because unlike compiled language like Golang where all dependencies are bundled and compiled in you executable file, Javascript bundlers don't. Your bundled code in dist still contains require or import statement to get dependencies from node_modules.
You can also run npm prune --production to remove any developpement dependencies and thus reduce the size of your node_modules folder. (I believe that yarn does it by default.)

copy package.json while building js library with parcel js

I am creating a typescript library, and when I am bundling it with parcel.js, the package.json file is not getting copied into the dist folder. Can any one let me know how can it be done?
You could accomplish this by using the copyfiles package and modifying your build script to copy the package.json file to the dist folder after parcel runs. (e.g. parcel build && copyfiles package.json dist).
However, the reason why parcel doesn't support this out of the box is that you probably don't want to do this. When you're making and publishing an npm library, there are a number of fields in your package.json that have special meaning - especially "main", but also "types" and "module". When you publish your library, you want to make sure that these fields point to the right thing.
When you run parcel build, parcel looks at these these fields in your package.json to decide where to put the output files.
So if you then copied your unmodified package.json file to the dist folder and tried to publish the dist folder as if it were your package, things would be broken for your users - the package.json's main field would point to dist/outputbundle.js, but the actual file would be at /bundleoutput.js.
If you want publish only a subset of the files in your project, the typical way to do this is to use the package.json files field to "whitelist" which folders get included when you run npm publish, without modifying the package structure (see docs).

Package only certain directories with asar in an Electron application

I have an Electron application where I am trying to use asar to package the node_modules and sources directories excluding the other directories.
I noticed when building the application with asar enabled, the whole app directory is packaged. This is not ideal because some executables and DLL's need to be available outside the asar file.
What I've tried
Currently, I have a script that packages the sources and node_modules directories (using asar). This script is executed after Electron-Forge has built the executable. But Electron does not seem to automatically check the asar file for source and node_module files. I receive the error "Error: Cannot find module index.js". This gives the wanted file structure, but does not work with Electron (see "File structure" below).
File structure
File structure before creating executable:
- node_modules/
- sources/
- executable/
- images/
Wanted file structure after creating executable:
- resource/
- app/
- executable/
- images/
- sources.asar
- node_modules.asar
or the following (where the app.asar file should only contain the sources/ and node_modules/ directory):
- resource/
- app/
- executable/
- images/
- app.asar
And it's mainly important that Electron knows when to use the asar file and when to use the files directly. Is it possible to configure it like this, or something similar?
Question
Is there any way to configure Electron/Electron-Forge to only package certain directories into asar files while copying the other directories into the resource/app directory?
In your package.json in "build" section add the following code:
"build": {
"asar": true,
"asarUnpack": [
"**/thefirstfolder/secondfolder/**/*"
],
},
This "**/thefirstfolder/secondfolder/**/*" will unpack everything that is the child of secondfolder

yarn publish <folder>.gitignore overriding .npmignore

I'm trying to publish a module I have created.
The module has multiple entries in it and I want to publish from within my build folder.
Every time I try to publish with yarn. I get:
Output:
The following paths are ignored by one of your .gitignore files:
build/package.json
Use -f if you really want to add them.
I tried yarn publish build
And also cd build && yarn publish where I copy the package.json and npmignore and all the relevant files.
It's always the same result.
I have a .gitignore in my root and an .npmignore in my root.
If I publish the build folder from the root it works but I dont want the path to include the build/lib folder.
If I do yarn build && cd build && npm publish && cd ../ that will also work.
But I'd rather use yarn.
Does anyone have a solution for it?
All I want is to publish my already created build folder content. I have all the needed files there.
EDIT
After much research and looking into other packages,
I ended up just creating a small copy script that copies my essential files to a build folder and clears up my package.json from all unwanted items.
Then my ci publishes from the build folder.
That was our solution that we've implemented

Categories

Resources