Development only workspace - npm

I am planning to split some of the code in my project to NPM/Yarn workspaces. But some of the workspaces will be used only during development. Just to be clear, I am not referring to devDependencies for the workspace. The workspace itself is a devDependency of the root project.
How can I ignore these workspaces from a production installation?
yarn install --production --frozen-lockfile
installs the production dependencies for the dev only workspaces.
If I run the above command after removing the dev only workspace directories from the production server, the installation fails since the lockfile will be modified.
How can I maintain a development only dependency as workspace, and yet prevent its installation on production build. I don't particularly prefer Yarn, NPM or PNPM. I would appreciate suggestions that will work on any of them.

Related

NODE_ENV=production with react-app-rewired

I have installed react-app-rewired as dev dependency according to docs.
"devDependencies": {
//...
"react-app-rewired": "^2.1.8",
},
Now I'd like to make a production build. When I use
NODE_ENV=production yarn install
consequent yarn build says that react-app-rewired: not found (because it is in dev only).
Does yarn build implies production under the hood?
If so, why do I need all the dev dependencies to be installed to make a production build?
Should I get rid of NODE_ENV or move react-app-rewired to production then?
When making the production build (when you need to transform your code, generate built assets, etc.), you usually need to have the dev dependencies installed since the dev dependencies contain the build tools needed to transform/compile the code into production code. When running the actual production code that is built from running yarn build, then you'd only need to have the production dependencies installed.
So, before the app is actually built, you need to run yarn install without NODE_ENV=production. Once the app is built (i.e. once you've ran yarn build and you have all the code transformed, all artifacts generated, etc.), then you'd re-run yarn install but with production mode turned on (NODE_ENV=production yarn install) so yarn only installs the dependencies in the dependencies section of package.json (these are the dependencies that your transformed code would depend on, whereas the build tools like react-app-rewired are only needed at build-time).

Use yarn and npm in Gitlab CI

I have a project which runs, in Gitlab CI, Yarn v1.22.5.
Among all its dependencies, there is one which is a Github repository. It runs a prepare script and it has package-lock.json file. For that project is it used npm indeed.
When it comes to install that dependency, I can see (in the Gitlab CI console) the following warning:
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
It seems that Yarn tries to install that dependency but it noticed the package-lock.json file from npm.
Is there a way to avoid this?
I would like to understand if there is a way to use npm when it comes to install that dependency.

Migrate from npm to yarn concerning the modules installed globally

Just found out that yarn does not install same modules again and again in different projects and so you can recover some space from the hard drive, so my question...Is there a way to transfer or migrate npm modules installed globally to yarn and what exactly should be done, in every single project, which previously got it's dependancies through npm?

How do devDependencies work when you yarn add <package>?

If you have a project that depends on packageA and you yarn add packageA but packageA has a devDependency on packageB to build, shouldn't that cause packageA to not work for you? Since packageA won't be able to build unless its devDependencies are installed too?
I guess my main question is if a pacakge has a devDependency on a built tool like babel, how does it get built and work when it gets yarn added by a project? Shouldn't build tools like webpack be a normal dependency?
No, they shouldn't, because the package that is yarn added is already built in an environment where the devDependencies are available. For example, when a package needs babel or webpack to build, then during the publishing a built bundle is created in a CI/CD pipeline that is valid es5 code and that is what you pull from npm. No build required after that.
GOOD MORNING :)
If you are having dependency problems on your dependencies of package.json, it is very simple to solve =]
What happens is that the dependency modules that the modules of your project need (dependencies) must be installed in the global npm as a package node (module), that is:
npm install -g youPackageName
If you have already installed a module in other projects or in the current project and want to turn it into a global package, you can use the command:
npm link youPackageName

Speeding up NPM package install

When I deploy my app to AWS, it's copied into a new directory, so NPM will install all the same packages, during each deploy, which can take a lot of time. Most of these packages haven't changed between builds (if at all), so having it do a full npm-install seems like a waste.
My app server runs a bunch of different Node apps, so installing globally isn't an option. Instead I'd like to have the app store it's node packages in a location that isn't wiped out during deployment, but have the option to update packages as necessary during npm install.
Does NPM have a concept of an app-specific module directory that isn't located in a subfolder of an app? That way I can delete the app folder, and not have to reinstall the same packages over and over again.
I could achieve this by using symlinks, or migrating the current node_module directory.
If you lock down your dependencies versions, NPM is likely to cache the packages. So the installation wouldn't take much longer.
If you prefer not to do this, you can install dependencies globally and link them with the npm link command (which is basically creating a symlink yourself!). Then, it'll be up to you update the globally installed packages regularly.