When I install e.g. jQuery from Nuget into my VS C# project, jquery.js ends up in my packages folder. This is good, since I don't want to check this file into my source control, since it's not my code and I'm never going to change it - in this context it's the equivalent of a DLL I might get via a different package. So far, so good...
Why, then, does the package installer also copy the file into the project Scripts folder, when surely it would be better to add it to the project as a link to the file in the packages folder, much as a Nuget package DLL would be referenced by the project.
The team have decided to drop support for content files in nuget packages. And they are recommending to use other package managers for client side libraries like npm, bower etc. There is a built in support for them in studio 2015.
One of the reasons is that every time some client package was updated on npm repo one of the guys in microsoft team had to fetch it repackage into nuget and publish.
Check it out!
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.
I would like to use CanvasJS library in my project but it does not exist in bower packages, so I tried to install it from a local zip file that I downloaded from their website. After successful installation the bower.json file includes the library's version and local path
"canvasjs-1.9.8": "C:\\path\\to\\myfolder\\canvasjs-1.9.8.zip"
Then if I try to build the project using gulp (e.g gulp serve), the library is not automatically added in the of index.html, as it happens for all the other libraries.
Is it a problem that it was installed from a local file? Is there another way to add CanvasJS library to my project and to my index.html file which is automatically generated with gulp build?
Thank you.
You can use gulp-inject in order to automatically inject code inside your index for example. Here the link:
https://www.npmjs.com/package/gulp-inject
So you can manually download your library (please include the .js version not the .zip), put it inside your project and dynamically include it inside the index using that plugin, adding a new task inside your gulp serve/build process.
You can also think to provide support for the library in the bower repository. It will make it available through bower to you and to the other users too in the future, if they may need it.
If you want to create a bower package, please refer to the official documentation that is really well done:
https://bower.io/docs/creating-packages/
For the bower installation I followed the instructions of this answer, and I assumed that using the .zip file that I downloaded would work. Since it didn't, the solution was to unistall it, un-compress the zip file and install the local .js file of the library. Then gulp serve command included the library in the index.html.
For a Meteor project I want to make changes to a Meteor Core library file.
Is this possible and if so, how?
So far I've tried just copying the files into my project directory hoping that the respective Objects are just overwritten from the originals but the problem herewith was that dependent functions or variables were only defined locally.
Then I tried to git clone them into the project's packages directory like you would do with a community package, but that didn't function either since the clone command failed (fatal: repository ... not found) and also the package is not explicitly called in the .meteor/packages file.
Any idea?
Meteor allows having local packages in a project, including ones that override existing (community or core) packages.
While overriding a community package locally often simply requires cloning (or extracting or adding as submodule) the GitHub repository into the /packages folder, core packages currently live inside sub-directories of the main meteor/meteor repository, which makes cloning them trickier.
Overriding a core package may require you to manually apply changes to the package as Meteor or the package update (as Meteor used to be dependent on specific package versions).
Therefore, before taking such step, make sure that you actually need to do it.
Make sure that you cannot you make your changes using local files or your own local package (e.g, by wrapping or replacing a function or monkey-patching it).
There are a few approaches that I used in order to override a core package.
Clone the entire repository and link the directories
This is useful if you want to contribute your changes to the project. You should probably fork the repository and clone your own fork.
Clone the meteor repository:
git clone https://github.com/meteor/meteor.git
or
git clone git#github.com:<username>/meteor.git if you forked it
Link the package directory (in your project's packages directory)
ln -s ../../(...)/meteor/packages/
You can checkout the desired branch/commit and copy them to the local packages directory instead, of course.
Statically download only the package directory
There is a neat trick that allows you to download a given directory from GitHub using svn.
This is obtained by issuing:
svn export https://github.com/meteor/meteor/[trunk|branches/]/packages/
for example:
cloning ddp-client from the devel branch:
svn export https://github.com/meteor/meteor/branches/devel/packages/ddp-client
or from the master branch:
svn export https://github.com/meteor/meteor/trunk/packages/ddp-client
Notes:
As mentioned earlier, you may need to manually apply changes if you update Meteor.
Don't forget to add the package to the project (meteor add <package>) if you haven't already.
Meteor is expected to switch to NPM at some point (possibly in Meteor v1.5), so make sure to use the methods specified in this answer only for meteor's own packaging system.
I have been trying to use the twitter api on cordova visual studio, for this I need to use OAuth for authentication for requests. I would like to use the https://github.com/BoyCook/TwitterJSClient.git twitter client. The built in nuGet package manager does not have this library. How can I install this JS library in my cordova msvs?
I tried using npm on the command line to intall this library but I get this error. What does it mean?
It looks like this javascript library is published on NPM: https://www.npmjs.com/package/twitter-node-client. To add this to your project, open the package.json file and put this in your dependencies section:
"twitter-js-client": "0.0.5"
You'll then see the "Dependencies" node in solution explorer say "(Restoring...)", and soon you'll see a node_modules folder appear in solution explorer. If you don't, turn on "show all files". This is what you should see:
You can then copy the library files into your www folder and consume them in your app (hopefully they work with Cordova!).
Question 1 :
I am installing my project dependency libraries using npm and it gets stored in the npm_modules folder. Is it necessary to keep the copy of library like angular.js,angular-route.js in lib folder or vendor folder? I could see few people are using lib folder or vendor folders to store the library in the permanent manner. I am confused by seeing this.
Question 2:
Do I need to copy/paste the node_modules folder to production or just run the npm install command on the project folder's command prompt to install all the dependencies in production. How does a dependency library get promoted to production?
Thank you kindly for your advice.
It all depends on how you need to deploy your site to production, really. Ultimately, you will probably want to bundle all your JS files into one or a few files, which are minified and sent with gzip compression.
How you bundle them is up to you. There are quite a few options:
Browserify
Webpack
Grunt / gulp build process
And many more besides
As to whether you need to keep a copy of these bundled javascript files under version control, well I think that boils down to 1 key question: can you run a build process (such as one of the tools using NodeJS) on the production server, or on a build server that creates a zip file or installer? If so, then you don't need to include them, just get the build server or production server to check out the latest copy from version control, npm install and then run the build process.
But if the best you could do is have the production server check files out from source control, then you would want to include the final versions of the files to use in the repository.
Keeping generated files, such as your bundled javascript files, in your source control repo should be avoided where possible. Because otherwise, every commit has to contain the changes to the source files, and the corresponding change to the generated files as well. And the latter is just noise, and has to be ignored by every developer looking at a diff/patch for a commit.