项目作者: A-Tokyo

项目描述 :
🔧 Injects babel plugins into create-react-app without ejecting.
高级语言: JavaScript
项目地址: git://github.com/A-Tokyo/inject-babel-plugins-cra.git
创建时间: 2018-06-28T06:10:38Z
项目社区:https://github.com/A-Tokyo/inject-babel-plugins-cra

开源协议:MIT License

下载


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:

    1. const injectBabelPluginCRA = require('inject-babel-plugin-cra');
    2. injectBabelPluginCRA([
    3. // add a simple plugin
    4. { name: 'babel-plugin-relay' },
    5. // add a plugin with options
    6. {
    7. name: 'babel-plugin-react-css-modules',
    8. options: {
    9. generateScopedName: '[path]__[name]__[local]',
    10. },
    11. },
    12. ]);
  • 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:
      1. Array<{
      2. /* plugin name */
      3. name: string,
      4. /* plugin options */
      5. options?: { [string]: any }
      6. }> = []
  • options?:
    • description: Optional advanced options object
    • type:
      1. {
      2. /* The path to to the babel preset file */
      3. babelPresetFilePath?: string,
      4. /* The string to match against before injecting the plugins */
      5. stringMatcher?: string,
      6. } = {
      7. /** For older version of CRA*/
      8. babelPresetFilePath: './node_modules/babel-preset-react-app/index.js',
      9. stringMatcher: 'const plugins = [',
      10. }