How to force npm publish to include files (that are not required by the entry)? - npm

I have an npm project for generating packages. It contains a folder called templates. The files in templates are not required by the entry point index.js instead they are collected using fs. They are not appearing in the published version. I have tried adding files: ["templates"] to the package.json (and various combinations ("templates/*", "templates/**/*", "templates/something/somefile.js") but the files are never included. The only files in templates folder that appear are Licence and package.json.
How do I make npm include these files in the published version?
Edit: My project directory has a .gitignore file but that does not include the templates folder. It does not have an .npmignore file.

The reason that the License and package.json files are appearing in your templates folder, is because npm ignores any attempt to exclude these files.
I would check that you don’t have any .ignore files in your templates folder and also check further up the filesystem, does the folder that contains your project have one? What about it’s parent and so on?
Then try temporarily removing the .gitignore file as well.
Lastly try publishing from another machine if nothing else works.

Related

npm pack, include file from root folder of a package in a monorepo

I have a monorepo setup with some private packages and a couple of public packages that can be published. I have a few common files that are directly in the root folder. When I run npm pack I want to be able to pack a few common files from the root folder. Is there a way to do it? Creating symlinks didn't work. Providing '../../file' in files attribute of the package.json didn't work either (perhaps understandably as there is no way to specify the target location).
Note that I currently don't have lerna which seem to have special logic to temporarily copy the LICENSE.md file from root folder to the packages.
Looking for options other than manually creating a copy of the file in each package that can be published.
I managed to accomplish this using prepack and postpack scripts

Files missing with npm pack

I am building a npm module, in which I want to include two directories : /dist and /demo.
So far, my approach was to use the 'files' attribute, in package.json :
"files": [
"dist",
"demo"
]
When running npm pack, the tgz files successfully contains the demo folder, and the built files in /dist.
However, during the build phase, I added a shell script that is copying some files (generated mylib.js and mylib.css) to the /demo directory. And my problem is that npm pack does not care about these specific files, which are not included in the tgz (despite I can see them in my explorer).
However, if the shell script make changes to the content of /demo/index.html, these changes are included in the tgz.
How could I include the missing files?
Seems that I misinterpretated the problem:
if the files were not in the tgz, it is because I add a .gitignore in /demo, ignoring js and css files.
As I really don't want this files to be commited, the solution was to add a .npmignore file, with no rule matching css/js

should I add app.js file in gitignore for nodejs/vuejs app?

I am new to vuejs. Recently I noticed that when I pull, it says conflict in app.js file. But I can't find the issue as app.js file is big.
Sould I add this file to gitignore file?
what is best practice to work with vue js?
I imagine you are building to a folder /dist and the app.js being conflited is the one inside of it.
You should ignore the /dist altogether. This folder is generated on the building process, meaning everyone that runs the project will update and create it.
Here is the default vue-cli .gitignore:
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
Not that not anything here may be useful to put in your own .gitignore. But you should for sure have at least node_modules and /dist.
If you are building the Vue project by scratch then I can say the following, when building/compiling your Vue project, best practices say that you should handle your entire production ready project in a dist/ or build/ directory where your main app.js file where the conflicts you are having would occur. This directory is only reserved for deploying the app and is not saved into your code repository, hence on why you should add to the .gitignore file the directory that holds such production files.

React native - exclude compiling folder content

I am thinking of putting my folder with design files in my open source project but being afraid that they will be used within compiling for ios or android app.
Is there a way to exclude this folder?
Thank you in advance.
If it's an open source project, I think you should keep resources in your repo and add them to your projects .npmignore file. This way, when you get the module via npm install, the resource files won't even be in node_modules folder and users that use your open source project won't need to change anything in their config files.

Gulp less with images

Is there a way for gulp-less (or some other tool) to take the paths to images that are referenced in the .less/.css file and put the files to the destination folder?
Right now when I install a node module, I #import the css file from /node_modules/... directory to my main .less file and it will be included in the bundle, but the images that come with the module are still located under /node_modules/... folder which I don't plan to deploy so using a relative URL would be pointless.
You should consider using bower to split your dev dependencies (handled by npm, non-deployed stuff) and front-end libs (handled by bower, deployed stuff).
Using a .bowerrc like this, you can tell where to save the libs in you projects structure:
{
"directory": "./<your-public-folder>/libs"
}