component-directory-webpack-plugin

1.0.5 • Public • Published

What

Normally, Webpack looks for index file when the path passed to require points to a directory; which means there may have a lot of index files. It's also hard for debugging since the DevTools will report an error in index.

This plugin makes it possible to use the name of the directory as the name of the entry file, makes it easier to find.

Usage

Install the plugin:

npm install component-directory-webpack-plugin

Add the following to Webpack's config file:

  var ComponentDirectoryPlugin = require("component-directory-webpack-plugin");
 
  resolve: {
    plugins: [new ComponentDirectoryPlugin()]
    extensions: ['', '.js', '.jsx'],
  },
 

Then when import MyComponent from 'components/MyComponent' and the path "component/MyComponent" is resolved to a directory, Webpack will try to look for component/MyComponent/MyComponent.js as the entry.

If there is also an index file, e.g. index.js, and it should be used as entry file instead of the file with the same name of directory, pass true as the first argument when creating new instance:

  var ComponentDirectoryPlugin = require("component-directory-webpack-plugin");
 
  resolve: {
    plugins: [new ComponentDirectoryPlugin(true)]
    extensions: ['', '.js', '.jsx'],
  },
 

Tests

npm test

Build Status

Caveats

This plugin has been developed to work with Webpack 2 for similar plugins that work with Webpack 1 use Directory Named Plugin or Directory name as main Plugin.

Copyright

Copyright (c) 2016 Sebastian Deutsch / 9elements

This plugin is heavily inspired by the Directory Named Plugin which is unfortunately broken for Webpack 2.

Package Sidebar

Install

npm i component-directory-webpack-plugin

Weekly Downloads

7

Version

1.0.5

License

MIT

Last publish

Collaborators

  • sebastiandeutsch