J
J
Juniorrrrr2021-12-25 22:36:06
Node.js
Juniorrrrr, 2021-12-25 22:36:06

How to properly build a project on nodeJs?

There is a test project in which there are:
3-5 css files
10 pictures
3 ejs files
1 front.js file 1 server.js
file

There are all sorts of different assemblers on the front, but how to optimize and compress files on the back and is it necessary to do this?

Let me explain, there are 3 ejs files, in fact this is the same html, it is given by the server at a specific URL.
On the same front, one could use webpack and build the project with all files compressed.
How does this process happen when developing server code? in fact, how can I shrink images, css, ejs without crap, so as not to manually or configure webpack pointwise for certain files. Maybe there is some popular solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2021-12-26
@bingo347

The back can also be collected by assemblers, the same webpack has a settings preset for the node.
As for optimization, the same terser.js, which is included in the production build by default, in addition to compression, makes a number of code optimizations. But for a node that has been running for a long time, they may turn out to be less significant, since JIT v8 also makes its own optimizations, and functions that are run many times will probably be optimized by it. However, if it is possible to run the code through additional optimization, it is better to do so.
As for ejs, templates need to be compiled to js. In the case of a node, this can be done both during assembly and at the start of the application. The main thing is that compilation does not occur during request processing.
Images and css should be optimized when building the client code, they have nothing to do with the node at all. The node should not know about them at all, the maximum path after the assembly is to insert them into the template, although this is also solved by the assembly for good. The statics should be given to Nginx or analogues.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question