简体   繁体   English

具有第二个package.json的Pattern Lab

[英]Pattern Lab with second package.json

I have a Pattern Lab edition-node-gulp set up and would like to use NPM to manage UI dependencies, like jQuery, D3 and others. 我设置了Pattern Lab Edition-node-gulp ,并希望使用NPM来管理UI依赖项,例如jQuery,D3等。 Pattern Lab is set up so that development happens in a 'Source' folder, which is complied and moved to a 'Public' folder. 设置了Pattern Lab,以便在“源”文件夹中进行开发,该文件夹已编译并移至“公共”文件夹中。 The root of the Public folder becomes the root of the application when served. 提供服务后,公用文件夹的根目录将成为应用程序的根目录。

Currently, I include assets like jQuery and others manually. 目前,我手动添加了jQuery等资产。 I think it would be great to manage dependencies like jQuery right in the package.json file used to run all of Pattern Lab Node, but the node_modules folder exists outside of Public, so I can not reference it in the live application. 我认为最好在用于运行所有Pattern Lab Node的package.json文件中管理类似jQuery的依赖项,但是node_modules文件夹存在于Public之外,因此我不能在实时应用程序中引用它。

So far, it seems that I have two options: 到目前为止,看来我有两个选择:

  1. Continue as is, and forget package management for these assets. 照原样继续,然后忘记这些资产的软件包管理。
  2. Create a second package.json inside Public with jQuery and others, which seems sloppy. 使用jQuery和其他工具在Public内部创建第二个package.json,看起来有些草率。

Is creating a second package.json so bad? 创建第二个package.json很糟糕吗? Am I failing to consider some other option? 我是否没有考虑其他选择?

Creating a second package.json is not that bad (when you know what and how you are doing of course). 创建第二个package.json还不错(当然,当您知道自己在做什么和如何做时)。 However in your particular case it is not the best scenario because there are way better options. 但是,在您的特定情况下,这不是最佳方案,因为有很多更好的选择。

What is the problem? 问题是什么? Adding the assets to the build output. 将资产添加到构建输出中。 So, what you can do: 因此,您可以做什么:

  1. install the assets via npm install and save them in the original package.json 通过npm install安装资产并将其保存在原始package.json中
  2. adapt gulpfile.js to copy the files in the output directory. 修改gulpfile.js以将文件复制到输出目录中。

If the second step step is too hacky / problematic it could be also replaced with simple package.json scripts change (add build script): 如果第二步太过分/有问题,也可以将其替换为简单的package.json scripts更改(添加build脚本):

"scripts": {
  "gulp": "gulp -- ",
  "build": "npm run gulp && cp -R node_modules/jquery/dist/blablabla.js mypublicdir/blablabla.js"
},

and then run it as npm run build . 然后以npm run build身份运行它。 If you need to support Windows you can use https://www.npmjs.com/package/cp-cli instead of cp . 如果需要支持Windows,则可以使用https://www.npmjs.com/package/cp-cli代替cp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM