Minify javascript files with Node JS - node.js

We are using node js to minify javascript files in one single file. I want to know if there is a way to specify the order of the js files to be minified. Why? because we are using jquery-ui and moment datepicker. These two libraries are using a function that has the same name (datepicker). We are able to manage on the development environment to load first jquery-ui and after moment datepicker because we need the one on the moment datepicker file, so loading the files on this way, everything is good but when we end up on the deploying using Node JS, the jquery-ui comes at the end and overrides the moment datepicker and the datepicker is not working as expected. We are also using require js in our project. Any idea would be much appreciated.

Related

How to use node_module packages correctly

So, I'm heading to new territory in web dev.
I set up a basic npm project using npm init in my project folder. I don't have angular, react or any other Dev framework running. Basically I want to get started with some npm packages to easily update the things I need.
For my first test I picked bootstrap and font-awesome.
For testing I have a http-server running and displaying a index.html file from the public folder.
The site I'm displaying is a basic html site for now. How do I actually implementy packages the right way? Using <link rel="stylesheet" href="/path/to/node_modules/..."> is one option but not actually the way it is done, right?
Or will it be repacked once I'm ready for production. Since node_modules is not going to be transferred to the prod server.
Thank you very much in advance!
there is a difference between running javascript in nodejs and the browser javascript engine.
although nodejs is built on top of v8 javascript engine, nodejs is different in some ways, here are 2 of them:
nodejs is used mainly in server-side programming, where javascript is used for client-side
nodejs has builtin libraries which are not in the javascript specifications
if you are developing a client-side in nodejs (using react, angular or any other client-side frameworks), you will have to "convert" (a process called transpiling) it to run within the browser.
there are several tools which can help you in the process of transpiling your code. some famous ones are webpack and parcel in conjunction with babel (to pollyfill) to "build" your project and yield a bundled (few javascript file, usually one, that bundles all the javascript code into one of more files) javascript file(s), which are loaded by the webpage.
as you can see, once the project is bundled, node_modules directory has no use -- exactly what you want.

Reference compiled React javascript from Nodejs server

I have a React app that renders markup based on user input and I need to be able to render the markup the same way without a client. I've seen other people accomplish this by using Nodejs, is it possible to access React Components from Node given a reference to a compiled and minified Javascript file (this file is my React code bundled).
Yes, that is certainly possible with something like reactDOMServer. You can read more at: https://reactjs.org/docs/react-dom-server.html
What are you trying to do exactly? Are you trying to do it on a server? Or just on a command line? Are you using any bundlers like Webpack or Parcel?

Haxe nodejs split js, insted of one js

How can I generate separated js files, when use Haxe nodejs target?
Now I have one big js file, but I wanted to compile each class to separated js files.
I found modular-js, but if I think good, this is not work for nodejs (because AMD), just for frontend js.
thanks
Have you seen hxgenjs? It claims to support Node.js:
The default configuration emits one javascript file per Haxe class, and uses CommonJS (require()) to link the dependencies. It should work out of the box with your current Node.js project, React Native project or any other CommonJS-compatible runtimes.

Minimize Node js application .js files?

We have developed a desktop application using node webkit and it works fine. My only doubt is that, do we need to perform minification on the .js files written as part of node js server component. We usually perform minification on the javascript written mainly for UI view to reduce payload during loading of related javascripts of the HTML and also to hide coding information in the scripts so that its hard to modify.
So do we need to perform similar kind of concatenation and minification process on the node js server side .js files and then share the node webkit executable to the Customer. Without minification of node js files, the application works perfectly fine.
So, going back to my question -- Do we need to perform javascripts concatenation and minification for node js application?
Minification is generally to save bandwidth when downloading script files over the internet, so there isn't any real point to minifying your node.js files on your server if they aren't served anywhere.
I really doubt your server's storage needs to save a few kilobytes.

Combine and minify js file using nodejs dynamically

I am new to nodejs and grunt.
I was going through the less-middleware and was very impressed with the way it automatically creates the css files. I now want the same for js files also. Let me briefly explain -
User makes a request to site.min.js
The routes automatically captures the particular request.
Nodejs creates a new combined and minified js file based on the input parameters if the file is not already present.
Return the combined file.
I feel grunt is not the right way to go about it since every time the js files are updated I will have to commit new version of the min file to the repo. I want some dynamic mechanism of creating the minified version.
Also not that i am trying to deploy my code on heroku.
Grunt will compile your js files during the build. I'm not aware of a runtime pull-and-minify for javascript.

Resources