@mnrendra/rollup-plugin-alias
v1.1.0
Published
A Rollup plugin to resolve alias paths and automatically read the alias configuration from tsconfig.json.
Downloads
16
Maintainers
Readme
@mnrendra/rollup-plugin-alias
🍣 A Rollup plugin to resolve alias paths and automatically read the alias configuration from tsconfig.json
.
Install
npm i -D rollup-plugin-esbuild @mnrendra/rollup-plugin-alias
Usage
For ES modules (rollup.config.mjs
):
import esbuild from 'rollup-plugin-esbuild' // 'rollup-plugin-esbuild' is required
import alias from '@mnrendra/rollup-plugin-alias'
export default {
external: (id) => !/^[./]/.test(id),
input: 'your_input_file.(js|cjs|mjs|jsx|ts|cts|mts|tsx)',
output: {
file: 'dist/your_output_file.js',
format: 'cjs',
sourcemap: true
},
plugins: [
esbuild({ minify: true }), // <-- Require `esbuild` to be executed immediately before `alias`
alias() // <-- Execute `alias` immediately after `esbuild`. It will automatically read the alias configuration from `tsconfig.json`.
]
}
For CommonJS (rollup.config.js
):
const esbuild = require('rollup-plugin-esbuild') // 'rollup-plugin-esbuild' is required
const alias = require('@mnrendra/rollup-plugin-alias')
module.exports = {
external: (id) => !/^[./]/.test(id),
input: 'your_input_file.(js|cjs|mjs|jsx|ts|cts|mts|tsx)',
output: {
file: 'dist/your_output_file.js',
format: 'cjs',
sourcemap: true
},
plugins: [
esbuild({ minify: true }), // <-- Require `esbuild` to be executed immediately before `alias`
alias() // <-- Execute `alias` immediately after `esbuild`. It will automatically read the alias configuration from `tsconfig.json`.
]
}
Options
const alias = require('@mnrendra/rollup-plugin-alias')
module.exports = {
plugins: [
alias({
// List of alias configs to override alias path configurations from `tsconfig.json` or `compilerOptions` option.
aliases: [{
alias: '@',
path: './src'
}],
// `tsconfig.json`'s `compilerOptions` contains `baseUrl` and `paths` properties to override alias path configurations from `tsconfig.json`.
// Note: it will be overridden by the `aliases` option if it exists.
compilerOptions: {
baseUrl: './src',
paths: {
'@': ['./'],
'@/*': ['./*']
}
}
})
]
}
• aliases
type: Alias[]|undefined
default: []
List of alias configs to override alias path configurations from tsconfig.json
or compilerOptions
option.
• compilerOptions
type: CompilerOptions|undefined
default: undefined
tsconfig.json
's compilerOptions contains baseUrl
and paths
properties to override alias path configurations from tsconfig.json
.
Note: it will be overridden by the aliases
option if it exists.
Types
import type {
// @mnrendra/types-aliases
Alias,
Aliases,
// @mnrendra/types-tsconfig
CompilerOptions,
BaseURL,
Paths,
// @mnrendra/rollup-plugin-alias
Options,
Plugin
} from '@mnrendra/rollup-plugin-alias'