Giter Club home page Giter Club logo

babel-plugin-webpack-async-module-name's Introduction

Downloads

babel-plugin-webpack-async-module-name

This plugin use custom identifier to named webpack dynamic import modules, supports single or multiple modules.

Support Babel 6 and Babel 7.

Installation

npm i -D babel-plugin-webpack-async-module-name

Test

npm run test

Usage

Add the plugin to babelrc:

{
  "plugins": [
    "webpack-async-module-name"
  ]
}

Use in code:

importName('./a.js')

importName('./a.js', 'name-a')

importName(['./a.js', './b.js'])

importName(['./a.js', './b.js'], 'name-a-b')

It will be transformed to:

import('./a.js');

import( /*webpackChunkName: 'name-a'*/'./a.js');

Promise.all([import('./a.js'), import('./b.js')]);

Promise.all([import( /*webpackChunkName: 'name-a-b'*/'./a.js'), import( /*webpackChunkName: 'name-a-b'*/'./b.js')]);

License

MIT

babel-plugin-webpack-async-module-name's People

Contributors

dependabot[bot] avatar tgxhx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

babel-plugin-webpack-async-module-name's Issues

能否支持动态参数

importName('./Index.vue', 'chunkName') => OK

importName('./Index.vue', ${chunkName}) => undefiened

Does not work with dynamically set name.

When you want to dynamically assign a name to the import, the plugin fails.

Example code.

const componentList =[
  { id: 'SampleComponent' },
  { id: 'SampleReactApp' },
  { id: 'SecondSampleReactApp' }
];

for (let i = 0; i < componentList.length; i++) {
  let component = componentList[i];
  exists(component.id) &&
    importName('./components/' + component.id, component.id).then(
      module => new module[component.id]()
    );
}

可以支持变量嘛

大佬,传入的可以是变量么,或者说怎么样才能支持,比如说: 我去循环引入
importName(~/container/${name}/index)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.