Previously I would use NPM for server side stuff and Bower for frontend. NPM would install to the node_modules/
directory and I had a .bowerrc
to install those packages to public/lib
.
Now I've begun to use Yarn instead of NPM; and since they are pretty much 1:1 compatible it has been a smooth change.. However, now I'm wondering if I can ditch Bower and just use Yarn for everything. But I do not see a way (in either NPM or Yarn) to install normal packages to node_modules, but then have a sort of separate option to put some packages in public/
... Something similar to the --dev
option but instead it would be yarn add jquery --public
. Does anything like this exist?
One option, of course, would be to install all packages to the public/
directory but I believe this is a bad practice (correct me if I'm wrong).
Another option might be to have a separate package.json
in the public/
folder and run separate Yarn commands in there for frontend packages, but it's just a bit less convenient, I think; more error prone.
Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node. js module resolution algorithm.
Mixing npm and yarn should be avoided. Show activity on this post. Plus you get a warning from yarn as Dave Pile said because we have to push *-lock. json files changes you have to consider using npm version >= 7 to make sure whenever you install packages by npm it will update your yarn-lock.
Yarn is a package manager for your code. It allows you to use and share (e.g. JavaScript) code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don’t ever have to worry.
If you’re already familiar with npm, Yarn’s initialize command works the same way. Yarn will take you through a list of questions regarding your project. When in doubt, just press Enter for the default value that is presented in parentheses. After completing the final question, the console should print “success Saved package.json“.
You can use NPM packages for frontend AND backend. Any NPM package that you find might be intended for node only, browser only, or both. These days it seems like most packages can be used in both places.
However, Yarn creates and updates its lock file automatically when dependencies are being installed/updated. Secondly, Yarn is very fast. When installing dependencies for a project, NPM installs packages sequentially. This slows down the performance significantly. Yarn solves this problem by installing these packages in parallel.
The norm pretty much is something like:
yarn
gulp
, or module loader & bundler such as webpack
to create the bundles you need.
The gist of it is, install all the modules in a central place (using a package manager), then have a loader or other process grab and move the required assets to the location that you need to use them.
I'd suggest having a look at a kickstart project (pertaining to the stack that you're using) eg: I've used : Fountainjs in the past with success, or look into Yeoman if fountain doesnt strike your fancy (fyi. Fountain is built on top of Yeoman)
In pseudo commands:
1. yarn install /// installs all assets
2. gulp build /// cleans out current public folder, bundles & copies new
3. gulp serve /// runs your app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With