rollup-plugin-input-alias
v1.0.8
Published
rollup path aliases plugin
Downloads
14
Maintainers
Readme
rollup-plugin-input-alias
Rollup path alias plugin, similar to webpack's resolve.alias
, with simpler configuration.
Installation
pnpm
pnpm add rollup-plugin-input-alias --save-dev
npm
npm install rollup-plugin-input-alias --save-dev
yarn
yarn add rollup-plugin-input-alias --save-dev
Usage
// rollup.config.mjs
import inputAlias from 'rollup-plugin-input-alias';
export default {
plugins: [inputAlias({ alias: { '@': 'src' } })],
};
Configuration
alias
Type: Record<string,string>
Default: null
Alias configuration, where each key is an alias and the value is a relative path based on the working directory.
When Rollup resolves a file, if the path starts with an alias, the plugin will replace it with an absolute path (path.join(cwd, alias, the rest of source)
). If the path omits the file name, the plugin will attempt to find an index.xx
file in the directory in the order specified by extensions
. It will then calculate the relative path based on the file that imported this path and perform the replacement.
cwd
Type: string
Default : process.cwd()
Working directory path.
extensions
Type: string[]
Default: ['.js', '.ts'] | ['.ts', '.js']
When the file name is omitted (determined by path.extname
), it will look for an index.xx
file in the directory in this order, and throw an exception if not found.
The plugin will check if there is a tsconfig.json
in the working directory. If so, the default value is ['.ts', '.js'], otherwise it is ['.js', '.ts'].