lerna

从剖析Vue-cli源码出发完整的React业务脚手架实践(一)——脚手架架构基础搭建

为君一笑 提交于 2020-04-20 12:18:13
随着公司业务线增加了以后,基础脚手架已经满足不了需求,于是开始着手业务线的脚手架开发,我基于vue cli源码和自己的业务实践,吸取vue-cli插件模式的开发优势和业务结合,做一套关于React的项目脚手架。 写在前面 这是一篇长期持续更新的React脚手架实践,为的是吸取Vue Cli的脚手架经验,通过我们习惯的 插件-预设 的思想去构造我们的React业务脚手架,这可能不是最好的脚手架的开发实践,但是一定是 最完整的脚手架开发实践 。 全套实践我们将通过现有的vue cli源码一一解说的方式进行,一方面是为了熟悉成熟脚手架的代码实现,另一方面是为了完善自己的代码和实践的理解,让大家在自己开发脚手架或者学习的过程中,能有更深刻的认识。 脚手架架构 首先我们先给脚手架取个酷炫的名字吧,当时在做的时候突然看到一个图很酷,如下,是一个猫在抽烟 然后当时就爆出来杨超越的拍的照片有香烟的的新闻,当时解释到说是她家的猫在吸烟,当时就觉得就这个吧,感觉很酷炫!然后就取名叫做 cat-smoker 吧! 名字取完了,前期准备得整理一下架构思路和流程图,我自己整理出基于vue-cli的脚手架思维逻辑导图如下: 我们一开始的主体架构是两方面,一个是 cli 还有一个是 cli-service ,一个 主要在插件的基础上提供构造项目的能力 , 另外一个是为构造的项目提供基础服务(serve

从微前端聊聊架构演进

☆樱花仙子☆ 提交于 2020-02-25 18:42:24
就目前来看,微前端已经不是一个新话题了。随着越来越多的公司的深入研究,当前也提出了很多的解决方案。不过本文不是想要来介绍微前端,更想介绍项目如何一步步到达微前端架构的实际需求。 当然,也不排除有些项目在初期就需要微前端这样的架构,不过我一直相信,任何架构模式都是根据实际需求来构建的。为什么很多大公司投入那么多的精力去做这样一件事,更多的也是因为他们真正需要这样一种架构,甚至达到了不用会影响业务开发的可能。不过对于大部分企业,不太需要关注这一点。 事实上,无论是什么架构形式,都是为了项目能够更快的进行开发。 所以不难得出,ETC 原则 (Easier To Change ,易于修改) 贯穿始终。 对于 ToC 端应用而言,可能生存期只有 2,3 年就会结束或者重写。但是对于 ToB 端应用基本上是公司不关门之前都会持续开发和使用下去。当然很多 ToC 端应用提供的更多是服务而不是业务,他们更多的关注重点放在服务上而并非业务范畴。 单项目应用 对于后端开发而言,都是由单体应用开始的,但是对于前端开发,所谓单体应用的说法并不合适,所以我在这里把它叫做单项目应用。 对于一个刚刚开始的创业公司,是没有足够的人力储备以及代码实践。此时我们要做的就是利用脚手架开启项目进行开发。我们需要做的是做好代码规范,把代码写好。更多的考虑前端组件化与服务分离。 依赖注入

sending custom arguments to npm (yarn) scripts with lerna

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-04 07:51:11
问题 I have an issue when trying to pass arguments to an npm script with lerna . I have a node script that I want to run inside each package in the workspace. lerna docs suggests the following: { "scripts": { "my-script": "lerna exec -- node \\$LERNA_ROOT_PATH/scripts/my-script.js" } } so now, if I run in the root yarn run my-script it will run the script inside each package in the workspace. Sometimes, I need to scope the execution to a specific package. So running this from command line

How to build docker images in a lerna monorepo without publishing

你离开我真会死。 提交于 2020-01-04 02:43:49
问题 The use case for this is branch building and deployments in Lerna monorepos. The problem is that Lerna monorepos either hoist dependencies in NPM or use yarn workspaces to the same effect to collect all dependencies in the node_modules folder of the workspace/monorepo. Which means that they will not be accessible when building Dockerfiles in subfolders due to how docker build contexts work. I imagine what is needed here is a kind of "lower" (as opposed to hoist) function to pull package

Are there any advantages to using Lerna with Yarn workspaces?

不羁的心 提交于 2019-12-21 04:09:33
问题 We're in the process of migrating our monorepo to use Lerna. Lerna supports both NPM and Yarn and furthermore allows configuration of use with Yarn workspaces. It's unclear to me whether Lerna with Yarn workspaces has any distinct advantages to Lerna with NPM. Many posts claim that Lerna does more or less the same thing as Yarn workspaces out of the box. Are there any advantages to using Lerna with Yarn workspaces opposed to Lerna with NPM? 回答1: As far as I know, NPM doesn't have any

Install dependencies using lerna fails

℡╲_俬逩灬. 提交于 2019-12-13 03:48:21
问题 I am trying to add a module as dev-dependency from npm to one of several modules I have in my lerna repo, but when doing that neither is the module added to only one of my modules, nor is it added as a dev-dependency. Instead it is added to all of my local modules and it also is added as a normal dependency. I have created the following: mkdir FirstProject cd FirstProject yarn init yarn add lerna --dev npm run env lerna init mkdir packages/one mkdir packages/two cd packages/one yarn init cd .

Jest fails to transpile import from npm linked module

好久不见. 提交于 2019-12-07 08:45:41
问题 I have a project with multiple modules (using Lerna) and I want to use Jest to run tests. However, when I test code that uses a shared module (npm linked module via Lerna) it seems that Babel is not correctly applied and I get the following error: SyntaxError: Unexpected token import The structure of my project is like this: - my-project |- shared |- native |- web web and native require the shared module. When I go into the shared directory and run the local tests in Jest everything works

Monolithic repo and multiple node_modules folder

狂风中的少年 提交于 2019-12-07 05:39:00
问题 I have a project using monolithic repositories. Each packages has his own package.json file to manage dependencies for the said package. I'm using lerna to install package in all "sub-packages" of our monorepo app. The current project structure looks like this Project/ | package.json | node_modules/ |- packages/ |-- package1/ |--- package.json |--- node_modules/ |-- package2/ |--- package.json |--- node_modules/ I'm looking into a way of generalize common dependencies in the root node_modules

How to use Typescript's references and build mode to compile a mono repo to a serverless bundle?

旧时模样 提交于 2019-12-06 06:45:00
Typescript recently introduced a new feature to work with monorepos: references. By specifying references you can build all interdependent packages using tsc -b (see also this blog post ) This seems ideal for use with a large mono repo where some packages are serverless services. These services typically depend on one or more packages of the monorepo. I've created an example here: https://github.com/tommedema/serverless-mono-example While building works well with tsc -b , the problem is that the serverless framework needs to upload a single artifact .zip (to AWS in my case). When building a

Jest fails to transpile import from npm linked module

你说的曾经没有我的故事 提交于 2019-12-05 16:53:23
I have a project with multiple modules (using Lerna ) and I want to use Jest to run tests. However, when I test code that uses a shared module (npm linked module via Lerna) it seems that Babel is not correctly applied and I get the following error: SyntaxError: Unexpected token import The structure of my project is like this: - my-project |- shared |- native |- web web and native require the shared module. When I go into the shared directory and run the local tests in Jest everything works fine. If I run Jest tests in the web directory the above error occurs as soon as I include something from