1.0.1 • Published 7 years ago
@justinjung04/create-react-component v1.0.1
Create React Component
Create React components through CLI.
Install
npm install create-react-component --save-devRun
npx crcor
npx create-react-componentCreating
When the question comes up, you can write your component's name
Component name(s): MyButtonTo create multiple components, add the names with comma
Component name(s): Header, Body, FooterConfiguration
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 isfalse.test(boolean): Whether to create test file. Default isfalse.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
- Create template files in a folder. Note the naming convention
[filename].[extension].js.
- my-templates
- index.js.js
- index.css.js- Each template file is a JavaScript that takes
componentNameas argument and returns a new string.
module.exports = componentName => (
`console.log(Hello ${componentName}!);`
);- Add the custom template to
crc.config.js.
module.exports = {
custom: {
basePath: 'my-template',
template1: [
'index.js',
'index.css'
]
}
}- Run the command with
-coption (or--customoption).
npx crc -c template1CLI 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