marsladder-ui-component v1.13.0
marsladder-ui-component
marsladder-ui-component is a UI component library based on TypeScript and React. It integrates tools such as Prettier, ESLint, and Jest, and uses styled-components for style management. It is bundled and served using Vite, and automatically published to a private NPM registry using GitHub Actions.
Table of Contents
Installation
Ensure you have pnpm and Node.js installed (using NVM to manage versions).
pnpm install marsladder-ui-componentUsage
Import and use components from the component library in your project. For example, using the Button component:
import React from 'react';
import { Button } from 'marsladder-ui-component';
const App: React.FC = () => {
const handleClick = () => {
alert('Button clicked!');
};
return (
<div>
<Button onClick={handleClick}>Click Me</Button>
</div>
);
};
export default App;Development
Development and Debugging Mode
Use pnpm watch:dev to automate the local debugging workflow. This command will monitor source code changes, automatically build and update links, and start the development server.
Steps
Start Watching and the Development Server in the
marsladder-ui-componentProjectIn the root directory of the
marsladder-ui-componentproject, run the following command:pnpm watch:devThis command will start two processes simultaneously:
- Automatic Build and Link Watcher: Monitors changes in the
srcdirectory, automatically executespnpm buildandpnpm link --global. - Vite Development Server: Starts Vite's development server, allowing you to view changes to the component library in real-time.
- Automatic Build and Link Watcher: Monitors changes in the
Link
marsladder-ui-componentin the Target ProjectIn the target project where you need to use
marsladder-ui-component, run the following command to link the local component library:rm -rf node_modules/marsladder-ui-component pnpm link --global marsladder-ui-componentNote: Ensure that
reactandreact-domare already installed in the target project, asmarsladder-ui-componentspecifies these aspeerDependencies.Automatic Link Updates
When you modify and save a component in the
marsladder-ui-componentproject,pnpm watch:devwill automatically execute the following commands:pnpm build:all pnpm link --globalThis will automatically update the global link, ensuring that the
marsladder-ui-componentreferenced in the target project is always up to date. There is no need to run the above commands manually.
Example Workflow
Start Watching and the Development Server
cd path/to/marsladder-ui-component pnpm watch:devLink the Component Library in the Target Project
cd path/to/target-project rm -rf node_modules/marsladder-ui-component pnpm link --global marsladder-ui-componentDuring Development
- Edit and save component code in the
marsladder-ui-componentproject. pnpm watch:devwill automatically build and update the link.- The target project will automatically receive the latest component changes (you may need to restart the target project's development server to reflect the changes).
- Edit and save component code in the
Other Development-Related Commands
Only Watch Build and Link
If you only need to watch the build and link without starting the development server, you can run:
pnpm watchManual Build and Link
If you need to manually perform the build and link, you can run:
pnpm build pnpm link --global cd path/to/target-project rm -rf node_modules/marsladder-ui-component pnpm link --global marsladder-ui-componentNote: When executing this step manually, ensure that you have correctly linked both in the
marsladder-ui-componentproject and the target project.
Testing
Use Jest for unit testing.
Running All Tests
pnpm testRunning Tests with Watch Mode
pnpm test:watchCode Formatting and Linting
Formatting Code
Use Prettier to format the code:
pnpm formatChecking Code Quality
Use ESLint to check the code:
pnpm lintAutomatic Formatting and Checking Before Commit
With Husky and lint-staged, formatting and code checks are automatically run before each commit.
Publishing
The publishing process is automated through GitHub Actions. When code is pushed to the main branch, it is automatically built and published to the private NPM registry.
Manual Publishing
If you need to publish manually, you can run:
pnpm build
pnpm publish --access restrictedNote: Ensure that the main, module, and types fields are correctly configured in package.json.
NPM Registry
The package is available on npm.