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

babel-plugin-asyncmodule-import

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-asyncmodule-import

A babel plugin

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
37
1133.33%
Maintainers
2
Weekly downloads
 
Created
Source

babel-plugin-asyncmodule-import

A Babel Plugin,for react-asyncmodule, can be used for tranfroming async module importing.

Installation

npm i -D babel-plugin-asyncmodule-import

used in webpack babel-loader

{
    test: /\.(js|jsx)?$/,
    exclude: /node_modules/,
    use: [{
        loader: 'babel-loader',
        options: {
            plugins: [
                'asyncmodule-import',
                ...
            ]
        }
    }]
}

What it does

If you're using dynamic imports by react-asyncmodule

// when importCss set true
import AsyncModule from 'react-asyncmodule'; 
const AsyncComponent = AsyncModule({
    delay: 300,
    ...
});
const Home = AsyncComponent(import('./views/home'));  

 ↓ ↓ ↓ ↓ ↓ ↓  

import AsyncModule from 'react-asyncmodule';
const AsyncComponent = AsyncModule({
    delay: 300,
    ...
});
const Home = AsyncComponent({
    load: () => import( /*webpackChunkName: "home"*/'./views/home'),
    resolveWeak: () => require.resolveWeak('./views/home')
});
import AsyncModule from 'react-asyncmodule';
const AsyncComponent = AsyncModule({
    delay: 300,
    ...
});
// arrow function & magic comment compatibility
const A = AsyncModule({
    load: () => import( /* webpackPrefetch: true */'./a'),
    loading: 'LoadingView',
    error: 'ErrorView',
});
// arrow function in blockstament
const B = AsyncModule({
    load: () => {
        return import('./b');
    },
    loading: 'LoadingView',
    error: 'ErrorView',
});
// es6 object method
const C = AsyncModule({
    load() {
        return import('./c');
    },
    loading: 'LoadingView',
    error: 'ErrorView',
});

 ↓ ↓ ↓ ↓ ↓ ↓
 
import AsyncModule from 'react-asyncmodule';
const AsyncComponent = AsyncModule({
    delay: 300,
    ...
});

const A = AsyncModule({
    load: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "a"*/ './a')]),
    resolveWeak: () => require.resolveWeak('./a'),
    chunk: () => 'a',
    loading: 'LoadingView',
    error: 'ErrorView'
});

const B = AsyncModule({
    load: () => import( /*webpackChunkName: "b"*/'./b'),
    resolveWeak: () => require.resolveWeak('./b'),
    chunk: () => 'b',
    loading: 'LoadingView',
    error: 'ErrorView'
});

const C = AsyncModule({
    load: () => import( /*webpackChunkName: "c"*/'./c'),
    resolveWeak: () => require.resolveWeak('./c'),
    chunk: () => 'c',
    loading: 'LoadingView',
    error: 'ErrorView'
});

Css split can be implemented by extract-css-chunks-webpack-plugin

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