I am building a package for NPM and Bower.
I follow this pattern to keep the working files (ES6) in the src/ directory of my package and build my distribution files (ES5, compiled with Babel) in the lib/ directory.
In my .gitignore I ignore lib/.
On the one hand side (NPM), I have a .npmignore which ignores src/, instead of lib/. This is how I publish the lib/ folder contents on NPM.
On the other hand side (Bower), the lib/ folder is missing in the repository, therefore, the Bower package doesn't include it. How can I publish the ignored by git lib/ folder contents on Bower?
I think that's not possible.
The workaround I found is to commit the distribution files in the repository.
If they really piss you off - you could do this dirty trick: commit them right before you release a tag. Release a tag. Remove them.
Or simply drop the Bower support. But that's not a real solution to the problem, isn't it? :-)
Related
I built a small Node.js app and I want to put it on GitHub but the problem is node_modules is so large. Is there is any way to build the app and make it small?
To store you project on GitHub without node_modules you need to create a .gitignore in the root of your porject (beside the package.json file) and add node_modules entry to it.
The structure should look like this:
/project
...
package.json
.gitignore
package-lock.json // should NOT be added to the gitignore
And .gitignore should look look like this
node_modules
After that you need to push this .gitignore file to the remote repo (in your case to the GitHub).
By doing this you tell git to not track files which are inside the node_modules folder.
After pulling your project from remote (from GitHub) you will be able to get your modules back by using npm install which will install your dependencies inside node_modules folder.
Im using Restangular for HTTP requests. I want to use the method customPATCH. I can see it in the Restangular src/ directory here.
However when I ran 'npm install restangular' and pointed to the dist/ folder, I was getting the error "customPATCH is not a function". I noticed the source code in the dist/ folder isnt the same as what's in the src/ folder (it doesnt define the customPATCH method).
Why would there be a difference between what's in src/ and what's in dist/ for an NPM package? Are these normally kept in sync? In this case, the dist/ directory hasn't been updated in 8 months. Should I just use the source in the src/ folder? Maybe I'm misunderstanding how to use NPM packages (I always use the source in the dist/ folder)...
src/ and dist/ is a common naming convention for most packages. In most instances a developer has the code that they are working on src/ and the distribution version of the code they want others to use dist/. Most developers, my self included will either compile, minify or concatenate their code in to production facing version of the code. They usually include the src/ file in their public repositories so that people can see the source code and modify it as they see fit.
tdlr;
src/is the code the developer is working in.
dist/ is the distribution version that has been modified to perform better for users not looking to modify how the code works.
Typically src contains source code and dist code after minification and other changes (anyway, derived code - what would be target in Java world).
Sometimes when main repo is written in EcmaScript6 or newer, then dist folder contains code transpiled down to EcmaScript5 to support older versions of nodejs / older browsers.
You can use code from src if it works for you - however typically code in dist is minified and hence faster.
But sometimes authors forget to update dist folder and then you might have discrepancies. You might ping the author to rebuild the dist folder.
I've created npm package. In this package I'm using some modules which I put to node_modules to be able to require them as "modules", for example I have modules node_modules/my-module.js which I require in my code as require('my-module'). Now I do "npm publish" and then in another project I do "npm i" to install my module. It is installed but there are no my modules which I put to node_modules. I tried to add the next lines to .gitignore and to .npmignore, but it did not help:
node_modules/*
!node_modules/my-module.js
what do I do wrong?
I believe that all files in node_modules/ are ignored by NPM, so setting rules for node_modules in .gitignore and .npmignore will have no effect.
Additionally, everything in node_modules is ignored, except for bundled dependencies. npm automatically handles this for you, so don't bother adding node_modules to .npmignore.
Source
It's not clear to me why you want to have a package in the node_modules directory and not in the package.json file, but the short answer is that it's not possible, because that directory will be always ignored, as gauge said.
So there's two ways to go, you can put those modules in another directory and require it from his relative path or you publish those in NPM and then you require them from the package.json file.
Have you tried using something like:
!node_modules/
node_modules/*
!node_modules/my-module.js
I have that in a gitignore of mine and it has allowed publishing.
I am trying to understand how bower works..
If you look at jquery's github repo https://github.com/jquery/jquery you will see that the bower.json file points to dist/jquery.js. However, the repo does not include this folder on github, because the /dist folder is a product of the build step that is not checked into git (it is included in .gitignore).
So I am at a loss for how bower finds the dist/jquery.js file when it is not included in the git repo??
A couple of other points that should lead you on your way:
Gruntfile.js has a build task that outputs the built file to dist/jquery.js (see also build/tasks/build.js).
package.json has a dependency on grunt-bowercopy.
Related: Managing Bower components with Grunt
As #cbuckley said, the trick is that Bower will checkout from Git a tagged version instead of the master head. If you have a look at Jquery, the 2.1.1 tagged version has a jquery.js in dist/
I'm building a project and I want to split it up into different modules. I know I should put modules into node_modules/ but I want to commit the modules to the main version control for the time being (I'm using .gitignore to ignore the node_modules/ directory at the moment).
My current project setup:
services/
services/service1/package.json
services/service1/index.js
services/service2/package.json
services/service2/index.js
node_modules/*
app.js
package.json
My problem is it works with relative requires but the dependences in the services/*/package.json aren't loaded. Only the main package.json are loaded.
Is this a good approach? Is there a better one? What command can I run to install all the dependences? This is more of a problem for my CI/CD setup.
Thanks.
i found similar feature request here https://github.com/npm/npm/issues/4017 and seems you can't do it
one approach i see is to create soft links from node_modules to services you want and maintain them somehow
maybe you can use https://www.npmjs.org/doc/misc/npm-scripts.html postinstall script for this?