zoukankan      html  css  js  c++  java
  • lerna A tool for managing JavaScript projects with multiple packages.

    lerna

    https://lerna.js.org/

    https://github.com/lerna/lerna

    对于规模大的项目, 使用单独一个库管理, 但是内部分为多个package的情况;

    使用此工具管理。

    Splitting up large codebases into separate independently versioned packages is extremely useful for code sharing. However, making changes across many repositories is messy and difficult to track, and testing across repositories gets complicated really fast.

    To solve these (and many other) problems, some projects will organize their codebases into multi-package repositories. Projects like Babel, React, Angular, Ember, Meteor, Jest, and many others develop all of their packages within a single repository.

    Lerna is a tool that optimizes the workflow around managing multi-package repositories with git and npm.

    class big project folder

    https://github.com/lerna/lerna

    packages下专门存放公共模块

    src下面存放 各种app

    packages/
    ├── foo-pkg
    │   └── package.json
    ├── bar-pkg
    │   └── package.json
    ├── baz-pkg
    │   └── package.json
    └── qux-pkg
        └── package.json
    src/
    ├── admin
    │   ├── my-app
    │   │   └── package.json
    │   ├── stuff
    │   │   └── package.json
    │   └── things
    │       └── package.json
    ├── profile
    │   └── more-things
    │       └── package.json
    ├── property
    │   ├── more-stuff
    │   │   └── package.json
    │   └── other-things
    │       └── package.json
    └── upload
        └── other-stuff
            └── package.json

    应用-repo内依赖

    https://zhuanlan.zhihu.com/p/35237759

    增加依赖

    接下来,我们来为组件增加些依赖,首先House组件不能只由Window构成,还需要添加一些外部依赖(在这里我们假定为lodash)。我们执行:

    lerna add lodash --scope=house

    这句话会将lodash增添到House的dependencies属性里,这会儿你可以去看看package.json是不是发生变更了。
    我们还需要将Window添加到House的依赖里,执行:

    lerna add window --scope=house

    就是这么简单,它会自动检测到window隶属于当前项目,直接采用symlink的方式关联过去。

    symlink:符号链接,也就是平常所说的建立超链接,此时House的node_modules里的Window直接链接至项目里的Window组件,而不会再重新拉取一份,这个对本地开发是非常有用的。

     

    DEMO

    https://github.com/fanqingsong/code_snippet/tree/master/javascript/lerna-repo

    window

    export default function a() {
        console.log("window: hello world.")
    }

    house

    import window from "window"
    
    console.log("house call")
    window()

    ES module 和 commonjs

    http://www.ruanyifeng.com/blog/2020/08/how-nodejs-use-es6-module.html

    http://javascript.ruanyifeng.com/nodejs/module.html#toc0

    出处:http://www.cnblogs.com/lightsong/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    AppCrawler自动化遍历使用详解(版本2.1.0 )
    python 接口测试1 --如何创建和打印日志文件
    通过Xshell登录远程服务器实时查看log日志
    java基础知识6-- 抽象类,抽象方法,接口,构造方法,类方法等易混淆的知识点
    java基础知识5--集合类(Set,List,Map)和迭代器Iterator的使用
    java基础知识4--数组的常用方法(Array)
    java基础知识3--如何获取资源文件(Java中获取资源文件的url)
    java基础知识2--String,StringBufffer,StringBuilder的区别
    java基础知识1--String常用方法总结
    javascript正则表达式验证密码(必须含数字字符特殊符号,长度4-16位之间)
  • 原文地址:https://www.cnblogs.com/lightsong/p/15544415.html
Copyright © 2011-2022 走看看