Skip to content

Generate Production package.json when building #5849

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

Closed
tylkomat opened this issue Aug 8, 2022 · 6 comments
Closed

Generate Production package.json when building #5849

tylkomat opened this issue Aug 8, 2022 · 6 comments

Comments

@tylkomat
Copy link

tylkomat commented Aug 8, 2022

Describe the problem

It's not always clear which packages should go into dependencies and which ones into devDependencies. There are regular new questions about this topic.

Describe the proposed solution

The compiler has all the information about which packages can be inlined and which can't. It can create a minimal production package.json file which only inludes the necessary packages.

Alternatives considered

No response

Importance

would make my life easier

Additional Information

I already implemented the changes in kit and adapter-node, but I'm waiting for the big update until doing the PR.

@benmccann
Copy link
Member

This sounds like a duplicate of #3176

@tylkomat
Copy link
Author

tylkomat commented Aug 9, 2022

@benmccann It's not the same. I don't propose bundling the dependencies as not all can be bundled. My proposal merely converts this (example from my current project):

{
  ...
  "devDependencies": {
    "@felte/reporter-svelte": "1.1.2",
    "@felte/validator-vest": "1.0.9",
    "@playwright/test": "1.24.2",
    "@prisma/client": "4.1.1",
    "@sveltejs/adapter-node": "1.0.0-next.85",
    "@sveltejs/kit": "1.0.0-next.401",
    "@tailwindcss/forms": "0.5.2",
    "@tailwindcss/typography": "0.5.4",
    "@types/nodemailer": "6.4.4",
    "@typescript-eslint/eslint-plugin": "5.31.0",
    "@typescript-eslint/parser": "5.31.0",
    "autoprefixer": "10.4.8",
    "eslint": "8.21.0",
    "eslint-config-prettier": "8.5.0",
    "eslint-plugin-svelte3": "4.0.0",
    "felte": "1.2.2",
    "form-data": "4.0.0",
    "got": "12.3.0",
    "mdsvex": "0.10.6",
    "nodemailer": "6.7.7",
    "paseto": "3.1.0",
    "postcss": "8.4.14",
    "postcss-load-config": "4.0.1",
    "prettier": "2.7.1",
    "prettier-plugin-svelte": "2.7.0",
    "promise-retry": "2.0.1",
    "soap": "0.45.0",
    "svelte": "3.49.0",
    "svelte-check": "2.8.0",
    "svelte-preprocess": "4.10.7",
    "tailwindcss": "3.1.7",
    "tslib": "2.4.0",
    "typescript": "4.7.4",
    "vest": "4.5.0",
    "vite": "3.0.4"
  },
  ...
}

to this:

{
  ...
  "dependencies": {
    "@felte/validator-vest": "1.0.9",
    "@prisma/client": "4.1.1",
    "form-data": "4.0.0",
    "got": "12.3.0",
    "nodemailer": "6.7.7",
    "paseto": "3.1.0",
    "soap": "0.45.0",
    "vest": "4.5.0"
  }
  ...
}

I tried using ssr.noExternal and then for example prisma is missing. So I have to go back an tweak the call. I didn't try further, but I may end up with the same list of dependencies.
My proposal is a straight forward solution.

@benmccann
Copy link
Member

I don't propose bundling the dependencies as not all can be bundled

Why can't they? How do you figure out which can and can't?

@tylkomat
Copy link
Author

tylkomat commented Aug 9, 2022

Why can't they?

I don't know why they can't. I just know that they aren't.
I only have basic knowledge of vite, but this is what I see in the build result.
If packages can be inlined vite will compile them and import them locally from _app/immutable/chunks, otherwise the import stays unchanged. This is true for node internal modules i.e. fs, path, crypto, but also other packages. Node will look in the node_modules folder for these packages, so these are the packages which have to be in dependencies.
My guess is that they are not ES6 compatible. You can see examples of packages that behave that way here:

{
  ...
  "dependencies": {
    "@felte/validator-vest": "1.0.9",
    "@prisma/client": "4.1.1",
    "form-data": "4.0.0",
    "got": "12.3.0",
    "nodemailer": "6.7.7",
    "paseto": "3.1.0",
    "soap": "0.45.0",
    "vest": "4.5.0"
  }
  ...
}

How do you figure out which can and can't?

The vite compiler already figures that out when it alters the imports to some relative path or keeps them untouched.

You can look at the changes here, or I can just create the pull request. It is actually a small (I think) change and probably won't interfere with the big routing changes.

@benmccann
Copy link
Member

I tried using ssr.noExternal and then for example prisma is missing

Can you file an issue with a reproduction for this? It seems like we should fix this bug in Vite rather than work around it in SvelteKit

@tylkomat
Copy link
Author

I don't understand the fixation on ssr.noExternal. If vite can bundle the packages, it will, even without this setting.
If it can't, it won't. Forcing it with the setting ssr.noExternal may have side effects.

One year ago it was a default in createSvelte and has been removed (see #1016) because of issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants