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/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
  • 相关阅读:
    Oracle执行查询报错ORA-01034: ORACLE not available
    shell echo单行和多行文字定向写入到文件中
    oracle查看EM管理器状态显示Environment variable ORACLE_UNQNAME not defined. Please set ORACLE_UNQNAME to database unique name.
    正确使用 Element $confirm 方法,联调删除接口
    Express 统一配置响应头 header 方法
    jquery.i18n.properties.js 实现多语言
    navicat导出数据结构到word
    RabbitMQ用户角色及权限控制
    chrome谷歌浏览器自动填充用户名密码错位
    JVM性能调优参数整理
  • 原文地址:https://www.cnblogs.com/lightsong/p/15544415.html
Copyright © 2011-2022 走看看