🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

umd-package-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

umd-package-loader

umd 包加载器

latest
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

intro

tnpm i umd-package-loader --save
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

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

Keywords

loader

FAQs

Package last updated on 23 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts