Socket
Socket
Sign inDemoInstall

inject-babel-plugins-cra

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    inject-babel-plugins-cra

🔧 Injects babel plugins into create-react-app without ejecting.


Version published
Weekly downloads
183
increased by36.57%
Maintainers
1
Install size
9.45 kB
Created
Weekly downloads
 

Readme

Source

inject-babel-plugins-cra

🔧 Injects babel plugins into create-react-app without ejecting.

npm CircleCI npm

Getting started

Install the module

Run yarn add --dev inject-babel-plugins-cra.

Usage example

  • add the babel plugins you need to your project. e.g: yarn add babel-plugin-relay babel-plugin-react-css-modules.
  • create a js script that injects the plugins to your app, let's call it init.js. e.g:
    const injectBabelPluginCRA = require('inject-babel-plugin-cra');
    
    injectBabelPluginCRA([
      // add a simple plugin
      { name: 'babel-plugin-relay' },
      // add a plugin with options
      {
        name: 'babel-plugin-react-css-modules',
        options: {
          generateScopedName: '[path]__[name]__[local]',
        },
      },
    ]);
    
  • Update your start script in package.json to call the init.js script first.
    • e.g "start": "node ./init.js && npm-run-all -p watch-css start-js"

Docs

params:
  • plugins:
    • description: Plugins to be injected
    • type:
      Array<{
        /* plugin name */
        name: string,
        /* plugin options */
        options?: { [string]: any } 
      }> = []
      
  • options?:
    • description: Optional advanced options object
    • type:
      {
        /* The path to to the babel preset file */
        babelPresetFilePath?: string,
        /* The string to match against before injecting the plugins */
        stringMatcher?: string,
      } = {
        /** For older version of CRA*/
        babelPresetFilePath: './node_modules/babel-preset-react-app/index.js',
        stringMatcher: 'const plugins = [',
      }
      

FAQs

Last updated on 25 Jul 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc