Skip to content

CaoMeiYouRen/ns-import

Repository files navigation

ns-import

Version GitHub Workflow Status Documentation Maintenance License: MIT

Import/Require with namespace. 基于命名空间的 import 和 require。

主要代码和灵感参考自:https://github.com/shigma/ns-require

在此表示感谢。

🏠 主页

https://github.com/CaoMeiYouRen/ns-import#readme

📦 依赖要求

  • node >=16

🚀 安装

npm install ns-import

👨‍💻 使用

**注意:ES modules 和 CommonJS 两种使用方法不可混用! **

本项目仅适用于 NodeJS 端!无法在浏览器中运行!

在 ES modules 中使用

// 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 中使用

// 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`

🛠️ 开发

npm run dev

🔧 编译

npm run build

🔍 Lint

npm run lint

💾 Commit

npm run commit

👤 作者

CaoMeiYouRen

🤝 贡献

欢迎 贡献、提问或提出新功能!
如有问题请查看 issues page.
贡献或提出新功能可以查看contributing guide.

💰 支持

如果觉得这个项目有用的话请给一颗⭐️,非常感谢

🌟 Star History

Star History Chart

📝 License

Copyright © 2023 CaoMeiYouRen.
This project is MIT licensed.


This README was generated with ❤️ by cmyr-template-cli

About

Import/Require with namespace. 基于命名空间的 import 和 require

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •