简体   繁体   English

有没有办法在package.json中自动构建依赖项?

[英]Is there a way to automatically build a dependency in package.json?

I use firebaseui, and I need to build it with french localization because the localized versions are not published to npm. 我使用firebaseui,我需要使用法语本地化来构建它 ,因为本地化版本不会发布到npm。 My current package.json looks like this: 我当前的package.json看起来像这样:

"dependencies": {
    "firebaseui": "^3.5.2"
}

Is there a way to change it so that firebaseui is built with build-js-fr parameter on npm install ? 有没有办法改变它,这样firebaseui与内置build-js-fr参数上npm install

As we can find in this Github issue : 我们可以在这个Github问题中找到:

[Localization] May come later down the road. [本地化]可能会在以后的路上来。

I would not recommend having a local fork with your own build, because you will diverge from the main repo thus loosing upgrades and such. 我不建议你有自己的构建本地分叉,因为你将偏离主回购因此失去升级等。 However, a comment on this issue suggest using patch-package , an npm module that would allow you to make a "band-aid". 但是,对这个问题的评论建议使用patch-package ,这是一个允许你制作“创可贴”的npm模块。 Seems fine by me. 我觉得很好。

So I would suggest the following plan : 所以我建议以下计划:

  • You update the way firebaseui is built, directly inside your node_modules folder. 您更新的方式firebaseui建成后,直接在里面node_modules文件夹。
  • Then npx patch-package firebaseui , which will create a paches/firebaseui-3.5.2.patch . 然后npx patch-package firebaseui paches/firebaseui-3.5.2.patch ,这将创建一个paches/firebaseui-3.5.2.patch
  • Add this folder to your source control, and every team member will get the patch on npm i . 将此文件夹添加到源代码管理中,每个团队成员都将在npm i上获取补丁。
  • Once the firebaseui lib get i18n right, you ditch the patch. 一旦firebaseui lib获得i18n,你就会抛弃补丁。

Here's a more direct solution, I don't recommend it and it's only a proof of concept to get you started, but you can use the postinstall script in package.json to execute a script after npm i . 这是一个更直接的解决方案,我不推荐它,它只是一个概念证明让你入门,但你可以使用package.jsonpostinstall脚本在npm i之后执行一个脚本。

You would have something like this: 你会有这样的事情:

"script": {
    "postinstall": "./postinstall.sh",
}

Create the postinstall.sh script and make it executable: 创建postinstall.sh脚本并使其可执行:

touch postinstall.sh
chmod u+x postinstall.sh

Then you can clone the repo and build it directly, here's an example postinstall.sh : 然后你可以克隆repo并直接构建它,这是一个示例postinstall.sh

#!/usr/bin/env bash

git clone https://github.com/firebase/firebaseui-web.git
cd firebaseui-web
git checkout v3.5.2
npm i

for language in fr en es
do
    npm run build build-js-$language
done

But this will take a lot of time to run. 但这需要花费大量时间才能运行。 Marcel Falliere's solution sounds better. Marcel Falliere的解决方案听起来更好。 I tried running the build command from the firebaseui folder in node_modules . 我试图从运行构建命令firebaseui文件夹node_modules You'll need gulp , but you will hit an error due to missing gulpfile.js . 你需要gulp ,但是由于缺少gulpfile.js你会遇到错误。

I tested the solution posted above here on github: 我在github上测试了上面发布的解决方案:
https://github.com/GabLeRoux/npm-build-firebaseui-postinstall-example https://github.com/GabLeRoux/npm-build-firebaseui-postinstall-example

Note that this will probably fail on windows. 请注意,这可能会在Windows上失败。 This is only a proof of concept 🍻 这只是概念证明 🍻

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

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