https://github.com/caomeiyouren/ns-import
Import/Require with namespace. 基于命名空间的 import 和 require
https://github.com/caomeiyouren/ns-import
Last synced: 8 months ago
JSON representation
Import/Require with namespace. 基于命名空间的 import 和 require
- Host: GitHub
- URL: https://github.com/caomeiyouren/ns-import
- Owner: CaoMeiYouRen
- License: mit
- Created: 2023-11-29T07:15:45.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-06T12:18:35.000Z (over 1 year ago)
- Last Synced: 2024-05-17T20:54:24.901Z (over 1 year ago)
- Language: JavaScript
- Size: 54.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
ns-import
> Import/Require with namespace. 基于命名空间的 import 和 require。
>
> 主要代码和灵感参考自:https://github.com/shigma/ns-require
>
> 在此表示感谢。## 🏠 主页
[https://github.com/CaoMeiYouRen/ns-import#readme](https://github.com/CaoMeiYouRen/ns-import#readme)
## 📦 依赖要求
- node >=16
## 🚀 安装
```sh
npm install ns-import
```## 👨💻 使用
**注意:ES modules 和 CommonJS 两种使用方法不可混用! **
**本项目仅适用于 NodeJS 端!无法在浏览器中运行!**
### 在 ES modules 中使用
```ts
// Basic Usage
import { ns } from 'ns-import'const scope = ns({
namespace: 'awesome',
prefix: 'plugin',
})// 注意动态 import 需要配合 await 使用
await scope.import('foo') // will resolve to `awesome-plugin-foo`
await scope.import('@foo/bar') // will resolve to `@foo/awesome-plugin-bar`// With Official Scope
import { ns } from 'ns-import'const scope = ns({
namespace: 'awesome',
prefix: 'plugin',
official: 'scope',
})// 注意动态 import 需要配合 await 使用
await scope.import('foo') // will resolve to `@scope/plugin-foo`
// and then `awesome-plugin-foo`
await scope.import('@foo/bar') // will resolve to `@foo/awesome-plugin-bar`
```### 在 CommonJS 中使用
```ts
// Basic Usage
const { ns } = require('ns-import')
const scope = ns({
namespace: 'awesome',
prefix: 'plugin',
})
scope.require('foo') // will resolve to `awesome-plugin-foo`
scope.require('@foo/bar') // will resolve to `@foo/awesome-plugin-bar`// With Official Scope
const { ns } = require('ns-import')
const scope = ns({
namespace: 'awesome',
prefix: 'plugin',
official: 'scope',
})scope.require('foo') // will resolve to `@scope/plugin-foo`
// and then `awesome-plugin-foo`
scope.require('@foo/bar') // will resolve to `@foo/awesome-plugin-bar````
## 🛠️ 开发
```sh
npm run dev
```## 🔧 编译
```sh
npm run build
```## 🔍 Lint
```sh
npm run lint
```## 💾 Commit
```sh
npm run commit
```## 👤 作者
**CaoMeiYouRen**
* Website: [https://blog.cmyr.ltd/](https://blog.cmyr.ltd/)
* GitHub: [@CaoMeiYouRen](https://github.com/CaoMeiYouRen)
## 🤝 贡献
欢迎 贡献、提问或提出新功能!
如有问题请查看 [issues page](https://github.com/CaoMeiYouRen/ns-import/issues).
贡献或提出新功能可以查看[contributing guide](https://github.com/CaoMeiYouRen/ns-import/blob/master/CONTRIBUTING.md).## 💰 支持
如果觉得这个项目有用的话请给一颗⭐️,非常感谢
## 🌟 Star History
[](https://star-history.com/#CaoMeiYouRen/ns-import&Date)
## 📝 License
Copyright © 2023 [CaoMeiYouRen](https://github.com/CaoMeiYouRen).
This project is [MIT](https://github.com/CaoMeiYouRen/ns-import/blob/master/LICENSE) licensed.***
_This README was generated with ❤️ by [cmyr-template-cli](https://github.com/CaoMeiYouRen/cmyr-template-cli)_