babel-plugin-webpack-chunkname

Automatically set the chunkname for dynamic imports

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
babel-plugin-webpack-chunkname
36171.2.05 years ago6 years agoMinified + gzip package size for babel-plugin-webpack-chunkname in KB

Readme

babel-plugin-webpack-chunkname
NPM version NPM downloads CircleCI donate chat

Install

yarn add babel-plugin-webpack-chunkname

Usage

With .babelrc:
{
  "plugins": [
    "webpack-chunkname"
  ]
}

And it does this:
import('./pages/Home')

      ↓ ↓ ↓ ↓ ↓ ↓

import( /* webpackChunkName: 'pages/Home' */'./pages/Home')

And if you're using dynamic imports:
import(`./pages/${name}`)

      ↓ ↓ ↓ ↓ ↓ ↓

import( /* webpackChunkName: 'pages/[request]' */`./pages/${name}`)

Or using placeholder:
import(/* webpackChunkName: "__CHUNK_NAME__" */ `./foo`)

      ↓ ↓ ↓ ↓ ↓ ↓

import(/* webpackChunkName: "foo" */ `./foo`)

Options

getChunkName

  • Type: (imported: string) => string
  • Default: imported => imported.replace(/^[./]+|(\.js$)/g, '')

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

babel-plugin-webpack-chunkname © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).
egoist.moe · GitHub @EGOIST · Twitter @egoistlily