Socket
Socket
Sign inDemoInstall

@justinjung04/create-react-component

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @justinjung04/create-react-component

Create React components through CLI


Version published
Maintainers
1
Install size
185 kB
Created

Readme

Source

Create React Component

Create React components through CLI.

Install

npm install create-react-component --save-dev

Run

npx crc

or

npx create-react-component

Creating

When the question comes up, you can write your component's name

Component name(s): MyButton

To create multiple components, add the names with comma

Component name(s): Header, Body, Footer

Configuration

crc.config.js

Exports an object with following properties:

  • path (string): Base path for components to be created. Default is 'src/components'.
  • component (string): Type of React component. Accepts one of 'normal'|'pure'|'function'. Default is 'normal'.
  • typescript (boolean): Whether to create TypeScript files. Default is false.
  • test (boolean): Whether to create test file. Default is false.
  • stylesheet (string): Extension of the stylesheet. Accepts one of 'css'|'scss'|'less'|'none'. Default is 'css'.
  • custom (object): To fully customize templates and file componsitions. Accepts following properties:
    • basePath (string): Path to custom template folder. Default is 'crc-templates'.
    • [templateName] (array): Array of files to be generated from the custom template. For example, myTemplate: [ myTemplate.js.js, myTemplate.css.js ]

Using custom templates

  1. Create template files in a folder. Note the naming convention [filename].[extension].js.
- my-templates
  - index.js.js
  - index.css.js
  1. Each template file is a JavaScript that takes componentName as argument and returns a new string.
module.exports = componentName => (
`console.log(Hello ${componentName}!);`
);
  1. Add the custom template to crc.config.js.
module.exports = {
  custom: {
    basePath: 'my-template',
    template1: [
      'index.js',
      'index.css'
    ]
  }
}
  1. Run the command with -c option (or --custom option).
npx crc -c template1

CLI options

Usage: npx crc [options]

Options:

  -v, --version   Prints the version number
  -h, --help      Prints the help message
  -n, --normal    Create component(s) extending React.Component (default)
  -p, --pure      Create component(s) extending React.PureComponent
  -f, --function  Create function component(s)
  -c, --custom    Create custom component(s) based on custom templates
  --javascript    Create JavaScript files (default)
  --typescript    Create TypeScript files
  --test          Include test files
  --notest        Do not include test files (default)
  --css           Inlcude .css file (default)
  --less          Inlcude .less file
  --scss          Inlcude .scss file
  --nocss         Do not inlcude .scss file
  --path          Set path to the component folder

Keywords

FAQs

Last updated on 02 Apr 2019

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