Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Production Dependency Optimization By Running npm prune --production #2834

Open
PurnenduMIshra129th opened this issue Jan 7, 2025 · 12 comments
Assignees
Labels
feature request unapproved Unapproved for Pull Request

Comments

@PurnenduMIshra129th
Copy link

Is your feature request related to a problem? Please describe.
Currently production node_moudules have dev dependency present in it . So which is not required in production. This dev dependency is only required during development of application not in production.

Describe the solution you'd like
-If we want to to reproduce this issue . Then first build the application using 'npm run build' . Then run this command npm prune --production . If we start the server using this command 'npm run prod'. Then you can see some packages that are listed under development dependency is still used in production so you will see an error the modules is not found.

-So my approch is to to compare the dependecy used in production and development enviroment then which packages are used in both production but listed under development in package.json are removed under it and add into dependecy as production.

-As a result of this only devlopment dependcy will remove by prune command . And production packages are remain unaffected.

-It will optimize our packages for production enviroment by removing unwanted nodemodules.

-Around 200-300MB of node_modules size wiil decrease which is a significant size. Which is further be helpful for our docker production image built.

Describe alternatives you've considered

  • write two script first one is for comparision between development and prodution dependcy and genrate the output in json format.
  • Save the output of this script which will furhter be used .
  • By using diff command compare both the json files and list the common depnedcy that are used in production and development .
    -Then check if the common packages are listed under development dependecy or not . If it under the dev then it should be in production dependency list.
    -Then successfully executing both the script use the command npm prune --production . Then start the server by using npm run prod. If the server start with out error like nodemodules is not found . Then it solves our problem.

Approach to be followed (optional)
N/A

Additional context
ErrorDueToDevDependencyUninstall
package json_DevDependency

Potential internship candidates

Please read this if you are planning to apply for a Palisadoes Foundation internship

@github-actions github-actions bot added the unapproved Unapproved for Pull Request label Jan 7, 2025
@PurnenduMIshra129th
Copy link
Author

PurnenduMIshra129th commented Jan 7, 2025

@palisadoes plz check this one.This is one followup for the optimization for our docker image in prodution enviroment .plz assign . I have this script and working. This is a new feature that's why i opened this issue. If u want to implement this feature in my existing pr then i will make changes docker efficiency pr.

@adithyanotfound
Copy link

adithyanotfound commented Jan 10, 2025

@PurnenduMIshra129th These scripts are not required. The workflow that checks DockerFile will automatically fail if dependencies are not installed properly in future PRs. Currently just fix the dependencies in the package.json file itself so that npm prune works.

@PurnenduMIshra129th
Copy link
Author

PurnenduMIshra129th commented Jan 10, 2025

@adithyanotfound it is also required for normal optimize dependecy with out docker usages in production.It is not related to docker only . It is related to production nodemodules optimization by removing deve dependecy

@adithyanotfound
Copy link

it is also required for normal optimize dependecy with out docker usages in production.It is not related to docker only . It is related to production nodemodules optimization by removing deve dependecy

@PurnenduMIshra129th Wouldn't just adding a PR workflow be sufficient to ensure proper segregation between the dependencies?

@PurnenduMIshra129th
Copy link
Author

yes it will work but in this mehtod it dynamic means on future purpose whatever packages you will install before production you have to just run the command 'npm run move-prune' and every thing will be completed .First it will generate a list of production and dev dependency then by diff command it will compare it ,then the number of packages we get in this process . first it will uninstall it from the dev dependecy , then it will install it in production dependecy then it will remove all the dev dependecy but if we do this in workflow it will be manually. User have to dot it by him self . Lets no of common package we get is 10 which is listed in dev but used in production then for all those packages we have to manually delete it from dev then again add it production. So after ananlysis just tell me which one should be better , if workflow is better then i will go through that way.

@adithyanotfound
Copy link

@PurnenduMIshra129th Thanks for the detailed explanation. I understood it now. However

  1. The solution that you mentioned is only valid for fixing common dependencies.
  2. It does not ensure the segregation between dev and prod dependencies as mentioned in the issue description.
  3. Proper segregation is required for npm prune command to function properly.

@PurnenduMIshra129th
Copy link
Author

@adithyanotfound yes right . Because in production we only need the production dependency. So this approch will work for the future use if any of the packages misplaced in dev we can find it and move to prod depnedency. plz assign

@PurnenduMIshra129th
Copy link
Author

@palisadoes @adithyanotfound in which folder i will keep the script. If i will create new folder then what will be its name

@varshith257
Copy link
Member

Why new file folder? Keep it in root if it's related of dependencies

@PurnenduMIshra129th
Copy link
Author

PurnenduMIshra129th commented Jan 11, 2025

scriptANDjsonFiles
@varshith257 when we run the script then it will generate 4 json file one is for dev related , one is prod related dependency , one is common diff file of dev and prod , and last one is common dependency list so this files also stay in root file. If you want to stay this files (4files of json and 2 script files )in root then i will keep there.But i think if we create a separate folder for this script and json file then it will be clean ? comment your thoughts.

@varshith257
Copy link
Member

Ok create a new folder deps/

@PurnenduMIshra129th
Copy link
Author

@varshith257 @palisadoes check the pr . Give suggestion if any changes are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request unapproved Unapproved for Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants