New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-asyncmodule-tool

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-asyncmodule-tool

react asyncmodule tool

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

react-asyncmodule-tool

react-asyncmodule related method.

Installation

npm install react-asyncmodule-tool

Es6 used.

import {
    createCollect,
    createAssets,
    getChunkAssets
} from 'react-asyncmodule-tool';

API

createCollect(options)

options的属性

NameTypeDefaultDescription
chunkNamestring or array-当前 chunk 的名称,根据该值获取对应的资源文件,若为空则返回入口相关资源
statsobject-必填,webpack 构建生成的 stats,推荐使用 webpack-stats-plugin提取
outputPathstringstats 的 outputPath工程构建后 client 端的资源文件路径
entrypointsstring or array工程的 entry入口文件
asyncChunkKeystring-client 端获取依赖 chunk 的 domid
runtimeNamestring or array'runtime'从入口文件分离出的 runtime js文件
const collect = createCollect({
    stats,
    chunkName: 'home'
});

collect.getScripts(); // 返回 chunk 所需的脚本,含 async
collect.getStyles(); // 返回 chunk 所需的样式
collect.getInlineStyles().then((data) => { // 返回内联的样式
    console.log(data);
});

runtimeName一般不需要配置,使用默认值即可,如果有修改,则需要传入对应的 runtimeChunk 的名称,有多个 runtimeChunk 则传入数组,具体说明详见webpack runtime

createAssets(chunks, publicPath)

Serialized resource path based on the webpack's chunks

const assets = createAssets(stats);
// output
{
    a: {
        js: ['/public/a.js'],
        css: ['/public/a.css']
    },
    b: {
        js: ['/public/common.js', '/public/b.js'],
        css: ['/public/common.css', '/public/b.css']
    }
}

getChunkAssets(assets, chunkName)

Output chunkNames according to matchRoutes.

getChunkAssets({
   a: {
       js: ['/public/a.js'],
       css: ['/public/a.css']
   },
   b: {
       js: ['/public/common.js', '/public/b.js'],
       css: ['/public/common.css', '/public/b.css']
   }
}, 'a');

// output

{
   js: '<script type="text/javascript" src="/public/a.js"></script>',
   css: '<link href="/public/a.css" rel="stylesheet">'
}

Keywords

react

FAQs

Package last updated on 02 Apr 2020

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