-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref #64
- Loading branch information
Showing
18 changed files
with
264 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Shuimo UI Nuxt module | ||
|
||
[![npm version][npm-version-src]][npm-version-href] | ||
[![npm downloads][npm-downloads-src]][npm-downloads-href] | ||
[![License][license-src]][license-href] | ||
[![Nuxt][nuxt-src]][nuxt-href] | ||
|
||
[Shuimo UI](https://github.com/shuimo-design/shuimo-ui) module for [Nuxt](https://nuxt.com/) | ||
|
||
# Features | ||
|
||
- 🧩 Automatically import components and styles on demand. | ||
- ✨ Provide Some useful layout components. | ||
|
||
# Quick Setup | ||
|
||
1. Add `@shuimo-design/shuimo-ui-nuxt` dependency to your project | ||
|
||
```bash | ||
# Using pnpm | ||
pnpm add -D @shuimo-design/shuimo-ui-nuxt | ||
|
||
# Using yarn | ||
yarn add --dev @shuimo-design/shuimo-ui-nuxt | ||
|
||
# Using npm | ||
npm install --save-dev @shuimo-design/shuimo-ui-nuxt | ||
``` | ||
|
||
2. Add `shuimo-ui` to the `modules` section of `nuxt.config.ts` | ||
|
||
```js | ||
export default defineNuxtConfig({ | ||
modules: [ | ||
'@shuimo-design/shuimo-ui-nuxt' | ||
] | ||
}) | ||
``` | ||
|
||
That's it! You can now use Shuimo UI in your Nuxt app ✨ | ||
|
||
# Usage | ||
|
||
## Components: `MLoadingPreview` | ||
|
||
We provide a component called `MLoadingPreview`. | ||
you can used it when you want to do some time-consuming operations like preload some assets and show a loading animation. | ||
|
||
```vue | ||
<template> | ||
<div> | ||
<client-only> | ||
<MLoadingPreview v-model="isLoading" v-if="isLoading" :preInit="preInit"/> | ||
</client-only> | ||
<your-main-display-component v-if="!isLoading"> | ||
</your-main-display-component> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
const isLoading = ref(true); | ||
const preInit = async () => { | ||
await import('ASSET_URL'); | ||
// or other time-consuming operations | ||
return true; | ||
}; | ||
</script> | ||
``` | ||
|
||
<!-- Badges --> | ||
[npm-version-src]: https://img.shields.io/npm/v/shuimo-ui?style=flat&colorA=020420&label=shuimo-ui%40latest&color=861717 | ||
[npm-version-href]: https://npmjs.com/package/shuimo-ui | ||
|
||
[npm-downloads-src]: https://img.shields.io/npm/dm/shuimo-ui.svg?style=flat&colorA=020420&colorB=00DC82 | ||
[npm-downloads-href]: https://npmjs.com/package/shuimo-ui | ||
|
||
[license-src]: https://img.shields.io/npm/l/shuimo-ui.svg?style=flat&colorA=020420&colorB=00DC82 | ||
[license-href]: https://npmjs.com/package/shuimo-ui | ||
|
||
[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js | ||
[nuxt-href]: https://nuxt.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@shuimo-design/shuimo-ui-nuxt", | ||
"version": "0.0.1-beta.1", | ||
"description": "shuimo-ui nuxt module", | ||
"author": "阿怪 <[email protected]>", | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types.d.ts", | ||
"import": "./dist/module.mjs", | ||
"require": "./dist/module.cjs" | ||
} | ||
}, | ||
"main": "./dist/module.cjs", | ||
"types": "./dist/types.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"prepack": "nuxt-module-build build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/shuimo-design/shuimo-ui.git" | ||
}, | ||
"peerDependencies": { | ||
"shuimo-ui": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@nuxt/module-builder": "^0.5.5", | ||
"@nuxt/kit": "^3.10.3", | ||
"shuimo-ui": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @description shuimo nuxt module | ||
* @author 阿怪 | ||
* @date 2024/2/26 15:40 | ||
* @version v1.0.0 | ||
* | ||
* 江湖的业务千篇一律,复杂的代码好几百行。 | ||
*/ | ||
|
||
import { addComponent, addPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'; | ||
import { SHUIMO_ROOT_PATH } from './utils/shuimoPath'; | ||
import { readdirSync } from 'node:fs'; | ||
|
||
// Module options TypeScript interface definition | ||
export interface ShuimoNuxtModuleOptions { | ||
} | ||
|
||
const { resolve } = createResolver(import.meta.url); | ||
|
||
export default defineNuxtModule<ShuimoNuxtModuleOptions>({ | ||
meta: { | ||
name: 'shuimo-ui', | ||
configKey: 'shuimoUIModule', | ||
}, | ||
defaults: {}, | ||
hooks: { | ||
'components:dirs': async (dirs) => { | ||
// todo: use addComponent ? | ||
|
||
const typeDirentList = readdirSync(`${SHUIMO_ROOT_PATH}/dist/es/components`, { withFileTypes: true }); | ||
typeDirentList.forEach(d => { | ||
const dir = d.name; | ||
if (d.isDirectory()) { | ||
const nameDirentList = readdirSync(`${SHUIMO_ROOT_PATH}/dist/es/components/${dir}`, { withFileTypes: true }); | ||
nameDirentList.forEach(n => { | ||
if (n.isDirectory()) { | ||
dirs.push({ | ||
path: resolve(`${SHUIMO_ROOT_PATH}/dist/es/components/${dir}/${n.name}`), | ||
prefix: 'M', | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
|
||
}, | ||
}, | ||
async setup(options, nuxt) { | ||
nuxt.hook('nitro:config', async nitroConfig => { | ||
nitroConfig.publicAssets ||= []; | ||
nitroConfig.publicAssets.push({ | ||
dir: resolve(`${SHUIMO_ROOT_PATH}/public`), | ||
baseURL: 'm-shuimo', | ||
maxAge: 60 * 60 * 24 * 30, | ||
}); | ||
}); | ||
nuxt.options.build.transpile ||= []; | ||
nuxt.options.build.transpile.push('shuimo-ui'); | ||
|
||
nuxt.options.css.push(resolve(`${SHUIMO_ROOT_PATH}/dist/es/assets/style/global.css`)); | ||
|
||
addPlugin(resolve('./runtime/directive')); | ||
|
||
await addComponent({ | ||
name: 'MLoadingPreview', | ||
export: 'default', | ||
filePath: resolve('runtime/components/MLoadingPreview.vue'), | ||
}); | ||
|
||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.