Compressing all NodeJs JS files (node_modules) decreases performance?

0

In my application I'm using Gulp to compress all my JS files that are inside the node_modules folder, my question is about performance, it's a bad practice to do this or not?

If you have any suggestions, it will help a lot!

    
asked by anonymous 09.09.2016 / 14:54

1 answer

0

There are a number of ways to work with dependencies of modules installed via NPM.

Compressing every node_modules folder and deploying it, is never a good option. Aliases referencing your direct project to node_modules is not a good practice for several reasons, some of which are:

  • Some library can be updated via NPM and break your application
  • You will be compressing many files atoa, then inside the node_modules not only has the library that you use, without the prod version (not minified) has the developer version (minified) has test scripts, general README files etc etc.
  • A good practice is.

    You have the following structure (for example)

    node_modules/
    ----- angularjs/
    ---------- angular.js
    ---------- angular.min.js
    ---------- vários outros arquivos
    

    Your app here

    app/
    ----- js/
    ---------- libs/
    --------------- develop/
    -------------------- angular.js (aqui é o módulo do angular instalado via NPM sem ser minificadom usado geralmente para debug ou olhar o código para entender o que a library faz)
    dist /
    (dentro da pasta dist que seus arquivos vão estar todos minificados, otimizados e compactados)
    

    You can make this copy via GULP, GRUNT or even manually if you prefer.

    So also use GULP or GRUNT to minify the js files, (myfile.min.js) to deploy to the server.

    The good thing about this practice is if you wanted to upgrade some module, you can compare via any merge tool (WinMerge for example) and see what was actually updated or changed in relation to what you are using.

    So you can upgrade the modules without fear because they do not directly impact your application unless you choose to consciously upgrade them.

    In any case, never delpoy the folder node_modules.

        
    09.09.2016 / 15:43