1.4.1 • Published 6 months ago

dynamic-alias-resolve-plugin v1.4.1

Weekly downloads
8
License
ISC
Repository
github
Last release
6 months ago

dynamic-alias-resolve-plugin

npm.io

Introduction

Thanks for the help of enhanced-resolve, we can define alias for path, but it's static, in some cases we may want alias point to A path or B path, in other words, we want dynamic alias. enhanced-resolve is based on tapable, so we can write a plugin to make it.

Read this in other languages: english, 简体中文

Prerequisites

This module requires webpack v4 and above.

Installation

npm install -D dynamic-alias-resolve-plugin

Usage

In your webpack config, require() the dynamic-alias-resolve-plugin plugin as follows:

const DynamicAliasResolvePlugin = require("dynamic-alias-resolve-plugin");

and finally, add the plugin to your resolve configuration's plugins array

// https://webpack.js.org/configuration/resolve/#resolveplugins
resolve: {
  plugins: [
    new DynamicAliasResolvePlugin({
      // alias you want to make it dynamic
      alias: "@",
      // pathA or pathB should be replaced with real path
      // "request" is raw request object from enhanced-resolve
      // "alias" is matched alias of current request.(eg. "@" in "@/login.less")
      dynamic: (request, alias) => "pathA or PathB",
      // we just want less file to be handled by this plugin
      pattern: /\.less$/,
    }),
  ];
}

Options

propertiestypedefault
aliasArray\<string>'@'
dynamicfunction(request,alias)=>string|null|false|undefined()=>null
patternRegExp/.*/

Description Of Options

alias

alias you want to make it dynamic

dynamic

return value should be absolute path,all false value('',false,null) will be ignored. request is raw enhanced-resolve request object, alias is current alias you want make it dynamic. (eg. "@" in "@/login.less")

pattern

files needs handled by this plugin

1.4.1

6 months ago

1.3.1

6 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.2.1

2 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago