Registry / web-framework / directory-named-webpack-plugin

directory-named-webpack-plugin

JSON →
library4.1.0jsnpmunverified

Webpack resolve plugin that allows using a file named after its directory (e.g., foo/foo.js) instead of index.js as the entry point for directory imports. v4.1.0 supports Webpack >=4, with v2.x for Webpack 2/3 and v1.x for Webpack 1. Configurable via options like honorIndex, honorPackage, exclude, include, transformFn, and resolverHook. Provides fine-grained control over resolve behavior per directory, overcoming the limitation of always using index files.

npm install directory-named-webpack-plugin
INSTALL
IMPORT
SIG · DIRECTORY-NAMED-WE
D
directory-named-webpack-plugin
web-frameworkjavascriptv4.1.0
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.

DirectoryNamedWebpackPlugin
const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin');
import DirectoryNamedWebpackPlugin from 'directory-named-webpack-plugin';
This package does not provide a default ESM export; use CommonJS require(). For webpack config files, CommonJS is standard.
DirectoryNamedWebpackPlugin
const { default: DirectoryNamedWebpackPlugin } = await import('directory-named-webpack-plugin');
const { DirectoryNamedWebpackPlugin } = await import('directory-named-webpack-plugin');
ESM named import does not work because the package exports only as module.exports. Use default import via dynamic import.
new DirectoryNamedWebpackPlugin()
new DirectoryNamedWebpackPlugin({ honorIndex: true })
new DirectoryNamedWebpackPlugin(true)
Constructor accepts either a boolean (honorIndex shorthand) or an options object. Using a boolean may be confusing; prefer options object for clarity.

CommonJS webpack config using DirectoryNamedWebpackPlugin with exclude and include options.

const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin'); module.exports = { resolve: { plugins: [ new DirectoryNamedWebpackPlugin({ honorIndex: false, exclude: /node_modules/, include: [ path.resolve(__dirname, 'src/components'), path.resolve(__dirname, 'src/containers') ] }) ] } };
Debug
Known issues
breakingv4.x requires webpack >=4.0.0. Using with webpack 2 or 3 will fail.
fix
Use v2.x for webpack 2/3, v1.x for webpack 1.
affects: >=4.0.0 <5.0.0
gotchaBy default, honorIndex is false, so index files are ignored. If you expect index.js to be used as fallback, set honorIndex: true.
fix
new DirectoryNamedWebpackPlugin({ honorIndex: true })
affects: >=1.0.0
gotchaIf exclude does not cover node_modules, the plugin will also apply to external packages, potentially causing unexpected resolve behavior.
fix
Add exclude: /node_modules/ or specify include paths to restrict scope.
affects: >=1.0.0
deprecatedUsing a boolean argument instead of options object is deprecated in favor of the options object.
fix
Use new DirectoryNamedWebpackPlugin({ honorIndex: true }) instead of new DirectoryNamedWebpackPlugin(true).
affects: >=4.0.0
gotchaThe resolverHook option defaults to 'before-existing-directory'. Changing it to a different hook may cause the plugin to not work as expected.
fix
Only change resolverHook if you understand webpack's resolver plugins deeply.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'foo' from 'bar'
DirectoryNamedWebpackPlugin is not resolving the desired file because honorIndex is true and index.js exists, or include/exclude is misconfigured.
fix
Set honorIndex: false or ensure the directory has a file named after it. Check include/exclude settings.
TypeError: DirectoryNamedWebpackPlugin is not a constructor
Using ESM import incorrectly. This package is not an ESM default export.
fix
Use require('directory-named-webpack-plugin') or dynamic import with default property: const { default: DirNamedPlugin } = await import('directory-named-webpack-plugin')
Error: Hook 'before-existing-directory' is not supported (webpack deprecation)
Webpack removed or renamed the resolver hook used by default.
fix
Update the plugin to latest version or use resolverHook: 'directory' or 'resolve' as fallback (check webpack docs).
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency: works with webpack >=4.0.0
Agent activity
6 hits · last 30 days
node
6
Resources
directory-named-webpack-plugin — npm install directory-named-webpack-plugin · libregistry