Closed astik closed 3 years ago
What would be great:
@astik are you sure that the 20mb is due to email-templates? did you have other packages installed in your example above?
Yes, i'm pretty sure it is due to preview-email and its transitive dependency.
As you can check into https://github.com/astik/email-templates-test, there is a branch "as-peer-dependency-preview-in-dev" : https://github.com/astik/email-templates-test/commits/as-peer-dependency-preview-in-dev. As you can check in those 3 commits, there are only 2 dependencies : email-templates and pug ; nothing else: https://github.com/astik/email-templates-test/commit/ff707d5b56eec197370056c78a32667f7562880c In a separate commit, i add preview-email as devDependency: https://github.com/astik/email-templates-test/commit/ee80e2395d44774a5349a9e50f77982eec2dd0da
You also can try it by executing commands above. My fork of email-templates simply remove preview-email as dependency.
Probably just due to all the babel compilation stuff so we can support older versions of Node. I can just remove Babel and should be way more lightweight.
Problem i see is that i ship in production some dependencies that are only needed for dev. node_module is a problem that can be lighten but the fact that i ship too mush is another.
Maybe i'm overthinking it =/
Nah, you're right in that these are larger than they need to be. I'm saying the Babel stuff is on our side, e.g. https://github.com/forwardemail/preview-email/blob/master/package.json#L23
In my test repo, i added some npm list
results. For example, for preview-email: https://github.com/astik/email-templates-test/blob/master/npm-list/as-dev-dependency.txt#L192. A lot of dependencies are not deduped, which means they are not needed by email-templates (mailparser@2.7.7, pug@2.0.4, open@6.4.0, dayjs@1.8.28 and the babel you already mentionned: babel/runtime).
Out of the box people shouldn't have to do an extra step to get preview-email running locally
I think instead it might be best to try to strip out what's not needed in preview-email
If you want to PR this repo and add instructions for preview-email to README as well as modify source please do so, I'd prob accept that
Yes, i can see your point. Still, the other around is also valid : "Out of the box people shouldn't have to do an extra step to remove unneeded package from production build". As of today, I have no solution ... i'm not sure that NPM can allow this use case in one step in a satisfying way =/
Since commit e6ca0cd, preview-email is defined as a dependency. From our project point of view, it is a transitive dependency through email-templates. From our project point of view, preview-email should be a devDependency.
The current situation leads to an oversized node_module in production.
Whether we use the production flag or not, email-preview is fetched inside node_modules.
Node modules is 20Mo lighter without email-preview.
In dev (without production flag), we have the email-preview dependency and a 50Mo node_modules: this is expected. In production (with production flag), bundle is back to 30Mo as email-preview is not fetched anymore.
Having a lighter production node_module folder is better:
I cerated 2 repositories as example to reproduce the difference: