问题描述
以前我会将NPM用于服务器端和Bower用于前端。 NPM将安装到 node_modules /
目录,我有一个 .bowerrc
将这些软件包安装到 public / lib
。
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
.
现在我开始使用Yarn而不是NPM;因为它们几乎是1:1兼容所以它是一个平滑的变化..然而,现在我想知道我是否可以抛弃Bower并且只使用Yarn来做所有事情。但我没有看到(在NPM或Yarn中)将正常包安装到node_modules的方法,但是有一种单独的选项可以将一些包放在 public /
中。 ..类似于 - dev
选项,但它将是 yarn add jquery --public
。这样的事情是否存在?
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?
当然,一个选项是将所有包安装到 public /
目录,但我相信这是一个不好的做法(如果我错了,请纠正我)。
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).
另一种选择可能是拥有一个单独的包。 json
在 public /
文件夹中,并在那里为前端包运行单独的Yarn命令,但我觉得它不太方便;更容易出错。
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.
推荐答案
标准几乎是这样的:
- 通过
纱线安装包
- 使用任务运行器,例如,或模块加载器&诸如之类的捆绑包可以创建您需要的捆绑包。
- 这一切都取决于你的堆栈,显然有其他的,例如在过去我使用过.NET的本机捆绑,你可以实现相同的作为gulp / webpack ...再次由你来决定。
- Install packages via
yarn
- Use a task runner such as
gulp
, or module loader & bundler such aswebpack
to create the bundles you need.- This all depends on your stack, there are obviously others, for example in the past I've used .NET's native bundling, which you can achieve the same as gulp/webpack... again this is for you to decide.
我建议你看一下kickstart项目(与你正在使用的堆栈有关),例如:我是使用:
过去成功,或者查看如果喷泉没有引人注目(fyi。喷泉建在Yeoman之上)
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伪命令:
1. yarn install /// installs all assets
2. gulp build /// cleans out current public folder, bundles & copies new
3. gulp serve /// runs your app
这篇关于如何使用一个包管理器作为后端和前端? (纱线/ NPM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!