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

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

Related

Publish multiple packages from subfolders

So let's say I have a project called elements.
In this elements project I managed to do npm publish by adding .npmrc file and proper package.json to the root of the project.
What would be the best way to approach publishing if I was to introduce new components where every component is placed in a new folder and every component should be a separate package? Does then every subfolder need it's own .npmrc file with configuration? Can I somehow do a setup where I have endpoint and token in package.json and .npmrc files in root of the project but name of packages defined in subfolders?
Any input would be greatly appreciated, thanks!

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

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.

Should i delete webpack and other libraries after bundling?

NPM donwloads a lot of files needed for the webpack/libraries. From what i understand, webpack generates a one single bundle file, that contains all code for script working. After that, when i finish building my app, do i need to keep all those jquery/react files and webpack itself? Or should i just delete them?
It's common practice to make a project portable/shareable by following these steps;
Create a package.json and ensure to capture all dependencies,devDependencies and/or peerDependencies.
Add/commit this package.json and package-lock.json files to your version control
Create a .gitignore file and add node_modules to it (in essence, this cuts out that baggage)
For production purpose (e.g. to be shared with client finished product), build the project (which often results into a small files, often within /build or dist). And then you can always push that build file to AWS or Heroku or the clients' servers.
What does the above help you achieve?
You can easily start the project using any machine, as long as you run npm install which reads from your package.json.

NPM : Create an NPM package that adds files and folders to the project root directory

I've created a web app template that I use frequently for many different projects.
I would like to create an NPM package for it so that it's easier to install for new projects, separate the template from the project files, separate the template dependencies from the project dependencies, and allow easier updating of the template across all projects.
The issue I have is that I need some files/folders to be installed in the root directory (i.e. where package.json is saved). Most can go in the node_modules folder however I have some files that must be placed in the root directory.
For example, the template uses Next.js with a custom _app.js file. This must be in the root directory in a folder named pages. I also have various config files that must be in the root directory.
Can this be done with NPM, or does everything need to be installed in the node_modules folder? I'm having trouble finding anything on SO or Google that answers this, so if you happen to know a guide online on how to do this or can outline things I should search for it would be much appreciated.
With pure npm, everything has to go to the node_modules folder, so you can't solve your issue this way.
Maybe going with a templating tool such as grunt init or yeoman could be a solution here, although – unfortunately – you'll then lose some of the benefits of being able to install a package via npm.
Another option might be to use GitHub template repositories, which have just been introduced recently.
Last but not least one option might also be to just have the files' contents in the npm package, but create the pages/_app.js manually, but inside of it simply require the file contents from an npm module, and that's it. This at least helps to have the content portable, but of course it still asks you to setup the file and folder structure on your own.
Sorry that I don't have a better answer, but I hope it helps anyway.
PS: One "solution" might also be to use the postinstall step in an npm module's package.json file to create folder structure, copy files to where they should be and so on, but at least to me this feels more like a clumsy workaround than like a real solution.

Where should jspm_packages go in ASP.NET CORE?

I'm developing with ASP.NET Core, and am using jspm, with Visual Studio 2017 RC and WebStorm.
It seems that jspm init expects your absolute lowest level, root folder with EVERYTHING is always going to be wwwroot, and thus the path it establishes (and even more rigidly enforces in jspm 0.17.x beta) iswwwroot/jspm_packages`
However, a new ASP.NET Core project sets up with the node_modules directory, and by proxy the packages.json file, just outside of wwwroot.
Obviously, I can move the file - but it puzzles me that they're different. Some people say "just use a gulp task" but that isn't really an option. I tried that route and it was a complete nightmare to maintain. Plus, jspm seems to load things directly from its package store by default.
So which is it? Is there an inherit problem with the jspm_packages folder being a sibling to the wwwroot folder? Using the UseStaticFiles option in the configuration allows me to specify access to folders outside of wwwroot.
wwwroot is your public folder, this way, all your assets must be inside of it.
You can configure npm to install modules inside wwwroot folder. Take a look in this config page from npm documentation.
However, I recommend you to put your files outside the wwwroot folder, and then, send to wwwroot only the files you're gonna use.
Grunt and Gulp are very simple and useful. If you want to give it a try, take a look in this tutorial. There you can find an example of how to use Grunt with VisualStudio