Registry / devops / babel-plugin-path-chunk-name

babel-plugin-path-chunk-name

JSON →
library1.3.1jsnpmunverified

Babel plugin (v1.3.1, last updated 2020) that automatically names dynamic import chunks based on the file path, removing the need for manual webpackChunkName magic comments. It transforms import() to include webpackChunkName derived from the imported module's filename or directory structure. Options include 'delay' mode which wraps import in a function for lazy evaluation. Differentiates from manual comments and NamedChunksPlugin by automating chunk naming with zero configuration, preserving folder structure in output.

npm install babel-plugin-path-chunk-name
INSTALL
IMPORT
SIG · BABEL-PLUGIN-PATH-
B
babel-plugin-path-chunk-name
devopsjavascriptv1.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default export
module.exports = require('babel-plugin-path-chunk-name')
import plugin from 'babel-plugin-path-chunk-name'
CJS-only plugin; in Babel config use require() or string name.
Babel config string
plugins: ['path-chunk-name']
plugins: ['babel-plugin-path-chunk-name']
Babel resolves scoped plugins automatically; full name works but not required. Since v1.0.
Options
plugins: [['path-chunk-name', { delay: true }]]
plugins: ['path-chunk-name', { delay: true }]
Options must be in nested array; wrong placement causes them to be ignored.

Shows basic usage in .babelrc, default path-to-chunk-name transformation, delay mode wrapping, and dynamic import pattern.

// .babelrc { "plugins": ["path-chunk-name"] } // Input: import('./components/Header') // Output: import(/* webpackChunkName: 'Header' */ './components/Header') // With delay option { "plugins": [["path-chunk-name", { "delay": true }]] } // Input: import('./Foo') // Output: () => import(/* webpackChunkName: 'Foo' */ './Foo') // Dynamic path with [request] pattern // Input: import(`./base/${page}`) // Output: import(/* webpackChunkName: 'base/[request]' */ `./base/${page}`)
Debug
Known issues
breakingSince v1.0, dynamic import paths with variables are converted to '[request]' pattern; chunks may be grouped unexpectedly.
fix
Ensure dynamic paths are structured to generate desired chunk names, or use magic comments manually for fine control.
affects: >=1.0.0
gotchaThe 'delay' option wraps import in an arrow function; calling .then() after lazy import will cause the import to be invoked immediately (since v1.2.0).
fix
If using .then(), do not enable delay, or wrap import in a function manually to preserve lazy behavior.
affects: >=1.2.0
gotchaIf import is already in a delay wrapper (e.g., () => import('./foo')), the 'delay' option does nothing (since v1.3.0).
fix
Remove existing delay wrappers if you want the plugin to handle delay, or ensure consistency.
affects: >=1.3.0
deprecatedPlugin relies on Babel 6/7 API; compatibility with Babel 8 or future versions is not guaranteed.
fix
Consider alternative chunk naming strategies if upgrading Babel breaks the plugin.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'babel-plugin-path-chunk-name'
Plugin not installed or Babel cannot resolve it.
fix
Run `npm install babel-plugin-path-chunk-name --save-dev` and ensure it's in node_modules.
ReferenceError: require is not defined
Using import statement in .babelrc (ESM) while plugin is CJS.
fix
Use require() or string name in Babel config; avoid ESM imports for config.
Invalid plugin configuration: must be an array or string
Options passed as second argument to string plugin name without array wrapper.
fix
Use nesting array: `[["path-chunk-name", { opts }]]`.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
2
Resources
babel-plugin-path-chunk-name — npm install babel-plugin-path-chunk-name · libregistry