All Projects → F1LT3R → babel-loader-lerna-cra

F1LT3R / babel-loader-lerna-cra

Licence: MIT license
Transpile Create-React-App imports in Lerna projects.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to babel-loader-lerna-cra

eslint-plugin-import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 4,290 (+14200%)
Mutual labels:  import
import-cli-simple
This the meta package for Pacemaker Community, a Symfony based CLI application that provides import functionality for products, categories, attributes, and attribute-sets. The default format is CSV, adapters for XML are also available. The application can be declaratively extended by additional operations, which can be used to reassemble and exe…
Stars: ✭ 69 (+130%)
Mutual labels:  import
VBA-Import-Export
Export & Import VBA code for use with Git (or any VCS)
Stars: ✭ 14 (-53.33%)
Mutual labels:  import
Blended
The Most Versatile Static HTML Site Generator
Stars: ✭ 22 (-26.67%)
Mutual labels:  import
react-ecommerce
E-commerce monorepo application using NextJs, React, React-native, Design-System and Graphql with Typescript
Stars: ✭ 136 (+353.33%)
Mutual labels:  lerna
html-integrations
The official JavaScript library for MathType, the leading formula editor and equation writer for the web by Wiris
Stars: ✭ 36 (+20%)
Mutual labels:  lerna
eslint-config-welly
😎 ⚙️ ESLint configuration for React projects that I do. Feel free to use this!
Stars: ✭ 21 (-30%)
Mutual labels:  import
uno-game
🎴 An UNO Game made in Javascript
Stars: ✭ 93 (+210%)
Mutual labels:  lerna
commercetools-sdk-typescript
The e-commerce SDK from commercetools for JavaScript written in TypeScript.
Stars: ✭ 25 (-16.67%)
Mutual labels:  import
importar
R package to import/load packages or functions the 'Python' way
Stars: ✭ 17 (-43.33%)
Mutual labels:  import
fyndiq-ui
Library of reusable web frontend components for Fyndiq
Stars: ✭ 39 (+30%)
Mutual labels:  lerna
great-migration
Copy objects from Rackspace to S3
Stars: ✭ 15 (-50%)
Mutual labels:  import
qgis-kmltools-plugin
Fast KML Import and Export Plugin for QGIS
Stars: ✭ 45 (+50%)
Mutual labels:  import
skinner
Skin export / import tools for Autodesk Maya
Stars: ✭ 68 (+126.67%)
Mutual labels:  import
lint-deps
Lint for unused or missing dependencies in your node.js projects. Customize with plugins or configuration.
Stars: ✭ 48 (+60%)
Mutual labels:  import
lerna-starter
Simple React UI Development environment boilerplate to develop, test and publish your React components.
Stars: ✭ 55 (+83.33%)
Mutual labels:  lerna
excel mysql
Module for import Excel files to MySQL table and export MySQL table to Excel file using PHPExcel
Stars: ✭ 30 (+0%)
Mutual labels:  import
vue-cli3-lerna-ui
基于VUE CLI 3 & Lerna的UI框架设计
Stars: ✭ 73 (+143.33%)
Mutual labels:  lerna
janusgraph-util
util for janusgraph to import data and so on/Janusgraph 导数据等工具
Stars: ✭ 72 (+140%)
Mutual labels:  import
konan
find all require/import calls by walking the AST
Stars: ✭ 48 (+60%)
Mutual labels:  import

babel-loader-lerna-cra

Transpile Create-React-App imports in Lerna projects.

This package overrides the Webpack configuration of Create-React-App projects in a Lerna repo.

⚠️ Please Note

As with packages like React-App-Rewired...

Using babel-loader-lerna-cra breaks the "guarantees" that Create React App provides. That is to say, you now "own" the configs. No support will be provided. Proceed with caution.

"Stuff can break" — Dan Abramov https://twitter.com/dan_abramov/status/1045809734069170176

The Problem

Many people are trying to use Create-React-App in a Lerna repo with a project structure similar to this:

my-lerna-project/
├── lerna.json
├── package.json
└── packages
    ├── comp-a
    ├── comp-b
    ├── my-react-app-1
    │   └── comp-a
    └── my-react-app-2
        ├── comp-a
        └── comp-b

When running the React App, errors like these show up:

Error: You may need an appropriate loader to handle this file.
Failed to compile.

../comp-button/src/index.js
SyntaxError: .../monorepo-react/packages/comp-button/src/index.js: Unexpected token (4:4)

  2 |
  3 | const Button = ({ type = 'button', children, onClick }) => (
> 4 |     <div>
    |     ^
  5 |       <button type={type} className="button" onClick={onClick}>
  6 |         {children}
  7 |       </button>

These errors show up because the Webpack config in your Create-React-App does not look outside the React App's ./src directory for additional import dirs. In fact, how could it? It has no idea how you would configure your monorepo.

The Solution

This module (babel-loader-lerna-cra) allows you to configure Webpack config overrides in your Lerna project's package.json file; allowing babel to transpile imported Lerna packages using dev and prod.

Usage

  1. Install babel-loader-lerna-cra in your Lerna repo:

    npm i -D babel-loader-lerna-cra
  2. Configure the package.json in your Lerna root:

    {
        "name": "root",
        "private": true,
        "devDependencies": {
            "babel-learna-loader-cra": "*"
        },
        "babel-loader-lerna-cra": {
            "imports": "packages/comp-*/src",
            "apps":  "packages/*react-app*"
        }
    }
    • imports - glob pattern for imports that require transpiling
    • apps - glob pattern for app that need overriding
  3. Boostrap your React Apps with Webpack overrides:

    Note: you MUST complete step two first.

    npx babel-loader-lerna-cra

    You should see this output:

    babel-lerna-loader-cra: bootstraping...
    babel-lerna-loader-cra: config = {
      lernaRoot: '../monorepo-react',
      settings: {
        imports: 'packages/comp-*/src',
        apps: 'packages/*react-app*'
      },
      apps: [
        '../packages/my-react-app-1',
        '../packages/my-react-app-2'
      ],
      imports: [
        '../packages/comp-a/src',
        '../packages/comp-a/src',
        '../packages/comp-b/src'
        ]
    }
    babel-lerna-loader-cra: copying: my-react-app-1/... webpack.config.dev.js => backup.webpack.config.prod.js
    babel-lerna-loader-cra: copying: my-react-app-1/... webpack.config.replacement.js => webpack.config.dev.js
    babel-lerna-loader-cra: copying: my-react-app-1/... webpack.config.prod.js => backup.webpack.config.prod.js
    babel-lerna-loader-cra: copying: my-react-app-1/... webpack.config.replacement.js => webpack.config.prod.js
    babel-lerna-loader-cra: copying: my-react-app-2/... webpack.config.dev.js => backup.webpack.config.prod.js
    babel-lerna-loader-cra: copying: my-react-app-2/... webpack.config.replacement.js => webpack.config.dev.js
    babel-lerna-loader-cra: copying: my-react-app-2/... webpack.config.prod.js => backup.webpack.config.prod.js
    babel-lerna-loader-cra: copying: my-react-app-2/... webpack.config.replacement.js => webpack.config.prod.js

    Note: you will need to bootstrap again when:

    1. Installing packages in CI
    2. When a new create-react-app is added

Related issues

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].