animated-componentlib-hk
v1.0.1
Published
A react component library with animation.
Downloads
1
Readme
Initial Setup
npm init
create folder
src
andcomponents
create
index.js
insrc
npm install --save-dev react react-dom
add
peerDependencies
withreact
andreact-dom
inpackage.json
Story Book
npx sb init
install storybook
Create Component
- create file with component name in
component
folder - create
index.js
file withexport * from "./ComponentName"
- go to
index.js
file undersrc
withexport * from "./components/ComponentName"
Create Story Book Component
- create a
Name.stories.js
under stories folder - add the following code
import React from 'react';
import {storiesOf} from '@storybook/react';
import {ExampleComponent} from '../components/ExampleComponent';
const stories = storiesOf('App Test', module);
stories.add('App', ()=> {
return (<ExampleComponent/>)
});
- run
npm run storybook
to Dev the component
Roll-up
- run
npm install rollup rollup-plugin-babel @rollup/plugin-babel @rollup/plugin-node-resolve rollup-plugin-peer-deps-external --save-dev
- run
npm install --save-dev @babel/preset-react
- modify the
package.json
script add
"rollup-plugin-postcss": "^4.0.2"
- create a
rollup.config.js
on root folder
import babel from 'rollup-plugin-babel';
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
export default [
{
input: './src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
}
],
plugins: [
babel({
exclude: 'node_module/**',
presets: ['@babel/preset-react']
}),
external(),
resolve(),
]
}
]
- run
npm install rollup-plugin-postcss
- update the
rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
export default [
{
input: './src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
}
],
plugins: [
postcss({
plugins: [],
minimize: true,
}),
babel({
exclude: 'node_module/**',
presets: ['@babel/preset-react']
}),
external(),
resolve(),
]
}
]
- run
npm run build-lib
Minimize the dis by Terser
- import terser in
rollup.config.js
import {terser} from 'rollup-plugin-terser';
- update the
rollup.config.js
import babel from 'rollup-plugin-babel';
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
import {terser} from 'rollup-plugin-terser';
import postcss from "rollup-plugin-postcss";
export default [
{
input: './src/index.js',
output: [
{
file: 'dist/index.js',
format: 'cjs',
},
{
file: 'dist/index.es.js',
format: 'es',
exports: 'named',
}
],
plugins: [
postcss({
plugins: [],
minimize: true,
}),
babel({
exclude: 'node_module/**',
presets: ['@babel/preset-react']
}),
external(),
resolve(),
terser(),
]
}
]
Publish the package
- login the npm ac
npm login
- update the code with the following code on
package.json
"main": "dist/index.js",
"module": "dist/index.es.js",
- publish the lib
npm publish