以前,我会将 NPM 用于服务器端,将 Bower 用于前端。 NPM 将安装到 node_modules/
目录,我有一个 .bowerrc
将这些包安装到 public/lib
。
现在我开始使用 Yarn 而不是 NPM;由于它们几乎是 1:1 兼容的,所以这是一个顺利的变化。但是,现在我想知道我是否可以抛弃 Bower 并只使用 Yarn 来处理所有事情。但是我没有看到一种方法(在 NPM 或 Yarn 中)将普通包安装到 node_modules,但是有一种单独的选项可以将一些包放在 public/
中......类似于--dev
选项,而是 yarn add jquery --public
。有这样的东西吗?
当然,一个选择是将所有包安装到 public/
目录,但我认为这是一种不好的做法(如果我错了请纠正我)。
另一种选择可能是在 public/
文件夹中有一个单独的 package.json
并在其中为前端包运行单独的 Yarn 命令,但它只是少了一点我认为方便;更容易出错。
最佳答案
规范几乎是这样的:
- 通过
yarn
安装包 - 使用任务运行程序,例如
gulp
,或模块加载器和打包器,例如webpack
创建您需要的 bundle 。- 这完全取决于您的堆栈,显然还有其他堆栈,例如,过去我使用过 .NET 的 native 捆绑,您可以实现与 gulp/webpack 相同的效果……同样,这由您决定。
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.
我建议看一下 kickstart 项目(与您正在使用的堆栈有关)例如:我用过: Fountainjs过去用成功,还是调查一下Yeoman如果喷泉没有引起您的兴趣(仅供引用。喷泉建在 Yeoman 之上)
在伪命令中:
1. yarn install /// installs all assets
2. gulp build /// cleans out current public folder, bundles & copies new
3. gulp serve /// runs your app
关于javascript - 如何为后端和前端使用一个包管理器? ( yarn /NPM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46775214/