Giter Site home page Giter Site logo

0x01001011 / sample-monorepo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wixplosives/sample-monorepo

0.0 1.0 0.0 4.57 MB

Sample monorepo setup with yarn workspaces, typescript, and lerna

License: MIT License

TypeScript 71.13% JavaScript 28.87%

sample-monorepo's Introduction

sample-monorepo

Build Status

Sample monorepo setup with yarn workspaces, typescript, and lerna.

Setup explained

Tooling

  • Monorepo is installed using yarn.

    • Packages are automatically linked together, meaning you can do cross-package work within the repo.
    • devDependencies are common, and only appear in the root package.json. Easier to manage and upgrade.
    • Each package has its own scripts and dependencies. They are being installed in the root node_modules, using the same deduping mechanism yarn uses for single packages.
    • Adding new packages is as simple as dropping an existing package in the packages folder, and re-running yarn.
  • Monorepo scripts are being executed using lerna.

    • lerna publish - multi-package publishing.
    • lerna run - running package scripts.
    • lerna updated - shows changed packages (since last tag).
  • Sources and tests are written in strict TypeScript.

    • Common base tsconfig.json.
    • @ts-tools/node is used to run code directly from sources.
  • Testing is done using mocha and chai.

    • Light, battle-tested, projects with few dependencies.
    • Can be bundled and used in the browser.

Included sample packages

  • @sample/components

    • React components library.
    • Built as cjs (Node consumption) and esm (bundler consumption).
  • @sample/app

    • React application.
    • Uses the @sample/components package (also inside monorepo).
    • Built as cjs (Node consumption) and umd (browser consumption).
  • @sample/server

Basic structure and configurations

.github                  // CI flow configuration (GitHub Actions)
packages/
  some-package/
    src/
      index.ts
    test/
      test.spec.ts
    LICENSE              // license file. included in npm artifact
    package.json         // package-specific deps and scripts
    README.md            // shown in npmjs.com. included in npm artifact
    tsconfig.build.json  // config used to build for publishing

.eslintignore            // eslint (linter) ignored directories/files
.eslintrc                // eslint (linter) configuration
.gitignore               // github's default node gitignore with customizations
.mocharc.js              // mocha (test runner) configuration
.prettierrc.js           // prettier (formatter) configuration
lerna.json               // lerna configuration
LICENSE                  // root license file. picked up by github
package.json             // common dev deps and workspace-wide scripts
README.md                // workspace-wide information. shown in github
tsconfig.json            // common typescript configuration
yarn.lock                // the only lock file in the repo. all packages combined

Dependency management

Traditionally, working with projects in separate repositories makes it difficult to keep versions of devDependencies aligned, as each project can specify its own devDependency versions.

Monorepos simplify this, because devDependencies are shared between all packages within the monorepo.

Taking this into account, we use the following dependency structure:

  • devDependencies are placed in the root package.json
  • dependencies and peerDependencies are placed in the package.json of the relevant package requiring them, as each package is published separately

New devDependencies can be added to the root package.json using yarn:

yarn add <package name> --dev -W

Some packages depend on sibling packages within the monorepo. For example, in this repo, @sample/app depends on @sample/components. This relationship is just a normal dependency, and can be described in the package.json of app like so:

  "dependencies": {
    "@sample/components": "<package version>"
  }

sample-monorepo's People

Contributors

avivahl avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.