# umd-package-loader

> umd 包加载器

Latest version **0.0.4** (published 2021-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install umd-package-loader
pnpm add umd-package-loader
yarn add umd-package-loader
bun add umd-package-loader
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2021-02-23 |
| First published | 2021-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yzw7489757 |
| Maintainers | a7489757 |
| Keywords | loader, package-loader, component-loader, umd-loader |

## Links

- npm: https://www.npmjs.com/package/umd-package-loader
- npm.io page: https://npm.io/package/umd-package-loader

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2021-02-23
- 0.0.1-beta.1 (beta) — 2021-02-23
- 0.0.3 — 2021-02-23
- 0.0.1-beta.0 — 2021-02-23

## README

# intro

``` shell
tnpm i umd-package-loader --save
```

``` ts
import Loader from 'umd-package-loader';
const LazyLoadComponent = (): JSX.Element => {
  const [com, setCom] = React.useState(null)
  React.useEffect(() => {
    new Loader({
      url: 'https://xxx.js',
      name: 'xxx', // library name e.g. xxxCom
    }).loadScript().then(component => {
      const node = component.default;
      setCom(React.createElement(node))
    }).catch(err => {
      // dosomething
    })
  }, []);

  return com
}
```
 
support requirejs，When the page has requirejs, it will be loaded in the way of `require`.if not, will use `document.createElement('script')` load script.

be careful, must follow `commonjs` or `amd` standard, forever, `umd` better. e.g. webpack config

``` js
module.exports = {
  devtool: 'source-map',
  entry: {
    reactDemo: resolve(__dirname, '../appGrounds/react/index.tsx')
  },
  output: {
    library: "xxxCom", // moduleName, the loader prop
    libraryTarget: 'umd', // must
    filename: '[name].js',
    path: resolve(__dirname, '../entry/lib'),
  }
}
```

## 版本协议

MIT

---
_Source: https://npm.io/package/umd-package-loader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
