is it somehow possible to build NodeJS together with some selected JavaScript modules? I believe that for native modules, I should be able to achieve this with node-gyp, but I have no idea how to do this for JavaScript modules. The main idea is to be able to use custom application without npm install.
I know that I can use any of the bundlers like pkg or nexe, but this has some drawbacks with respect to the development...
Thanks!
You can include JS files as described in here.
Just add a link-module parameter.
> .\vcbuild link-module './myCustomModule.js'
Related
I have a problem which can be easily solved by importing an external JS library into Node.js. However, this library does not exist in NPM.
I found out an old solution on StackOverflow which seems to fix the problem. However, it looks wierd.
Is there a more convenient solution in 2k20 to use external JS library methods into my Node.js code?
If your library have a package.json: You can install the package directly from the git repository, for example npm install https://github.com/vendor-creator/vendor-package. NOTE that for this method to work, in cases where the module has to be built, the git repository should contain a dist/ folder containing the built code or have in its package.json, a prepare step responsible for building the package upon installation.
If your library does not have a package.json and is simply a vanilla JavaScript file like the Lodash JavaScript file, I would advise just like in the post you linked, to create a vendor.js file (.min if the script is minified), copy and paste the content of the file and require it. Be aware that some libraries using CDN and not NPM, are designed for browser environment and may lack CommonJS support preventing you from using require. In that case you'll have to modify the library source code.
If it's a small library, there is no need to create an advanced build system. If the library is stable, just copy and paste it and you'll be fine. When in doubt always follow the K.I.S.S principle.
Hey guys since I am learning angular js I am confused about angular js installation.
1) In some tutorials people have used angular js library just like we import jquery in HTML file.for e.g.
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"
2) and on the other hand npm is used to install angular which creates scaffolding of angular application.
So what is difference between these two methods?
Which one is best method?
It depends on your needs.
Installing angularjs with npm gives you the possibility to minify and concat all your javascript files in only one for exemple.
It allows you for example if you use babel to transpile your javascript es6 code into classic javascript file.
Another thing is that in some IDE (advanced code editors) like webstorm, you have some helpfull funcyions with for exemple automplete on the node modules or on the functions.
With webpack you can use the import statement to separate all your javascript files and combine them before.
In fact, if you have to create a big project with a lot of different files, you want better performances, you want to minify and concat all your files into a single file, use npm with gulp/webpack.
If you want to create a simple project for yourself and you don't want to take a lot of time to learn/configure all of that, use simple CDN.
hopes it helps you.
I'm trying to use a Node.js based component (https://github.com/leandrowd/react-responsive-carousel) in my Figwheel-based ClojureScript app.
Unfortunately I cannot find a "standalone", packaged Javascript file with react-responsive-carousel. Since my app is not run by Node.js, it cannot require etc.
Is there either an elegant way to reuse Node.js libraries from ClojureScript, or a solution to package any Node.js library into a standalone file?
You can use Webpack to turn the library and all its dependencies into a single JavaScript file which exports a reference for the library.
In carousel-module.js
global.Carousel = require('react-responsive-carousel').Carousel;
Check out the Webpack page for how to set up Webpack.
It's unfortunate that we still have to go through this convoluted method to use CommonJS libraries. I hope native support is coming soon.
If I install a module via npm, what is the proper way to use the code in my website? I mean simply making node_modules static seems ridiculous, but I can't figure out how to easily create a static folder with the few pieces of JS I want to use in it.
Of course there are symbolic links and a lot of hacks I can think of off the top of my head, but I was just curious if there is a known workflow/way to solve this problem that I simply haven't read about yet.
Browserify and Webpack are the tools usually chosen to bundle up modules managed through npm for deployment to be used client side.
You want webpack
webpack supports pre-processing files via loaders. This allows you to
bundle any static resource not only javascript. You can easily write
your own loaders running in node.js.
I have been creating projects using npm. For AMD I am using the native node require because it is convenient and does what I need it to do. To run my projects at the moment I am using grunt-watchify. This allows me to point a file of entry and a file of output. So at the moment it produces one file uncompressed or mangled.
I would like to know what is the best approach for compressing and mangling my final file. I have tried uglify after the file is built by watchify but it does not seem to work correctly. I feel that is a dirty hack anyway. So here is my questions?
What is the best way to build a node project into one file? Grunt library suggestions would be great. Any that support compression/minifying would also be great.
Thanks
Removed my dependency on grunt-watchify and now just use grunt-browersify and grunt-contrib-watch. I then use grunt-contrib-uglify and grunt-contrib-cssmin to minimize files afterwards.