webpack-resolve-component-source-plugin
Component source file resolver plugin of webpack.
Why
Convenient to do tree-shaking or optimize helper codes.
Example
; // main: "lib/index.js" // /cwd/node_modules/library/lib/index.js ↓ ↓ ↓ ↓ ↓ ↓ // /cwd/node_modules/library/src/index.js
Usage
// webpack.config.jsconst WebpackResolveComponentSourcePlugin = ; moduleexports = resolve: plugins: extensions: '.js' sourceDirectory: 'src' libraryDirectory: 'lib'
Options
extensions
- type:
String|Array|Object
- default:
.js
Extensions supported.
extensions: '.js' // short for js extensions: '.js' '.jsx' // short for js extensions: js: '.js' '.jsx' '.ts' '.tsx' css: '.css' '.less' '.scss' '.sass'
sourceDirectory
- type:
String|Array
- default:
src
Source directory to resolve file.
sourceDirectory: 'src' sourceDirectory: 'src' 'es'
libraryDirectory
- type:
String|Array
- default:
src
Library directory to detect.
libraryDirectory: 'lib' libraryDirectory: 'lib' 'es'
customResolver
- type:
Function
- default:
null
Custom resolver.
{ if /\/moment\.js/ return path; }
include
- type:
String|Array|RegExp|Function
- default:
null
Include packages.
include: 'full/path/file.js' include: 'full/path/file.js' 'full/path/file2.js' include: /\rax-/ { return /\/rax-/; }
exclude
- type:
String|Array|RegExp|Function
- default:
null
Exclude packages.
exclude: 'full/path/file.js' exclude: 'full/path/file.js' 'full/path/file2.js' exclude: /\/rax-/ { return /\/rax-/; }