paths remapping is not done for type declarations
See original GitHub issueIs it possible to use this plugin together with rollup-plugin-alias to replace mapped paths with their “true” paths and if not, would you have a recommendation for a plugin which could do that? I found this. But unfortunately it doesn’t resolve my problem or answers my question.
What I am trying to do; I am trying to replace the mapped paths / path aliases (i.e. @src
) with the correct path in the transpiled type files. I’ve tried with the setup below and everything compiles fine. However, my type declaration files that contain a reference to a mapped path are not replaced. So to give an example, I have a Callable.d.ts
file after transpilation that looks like
import { Instantiable, Instance } from '@src/Support/types';
declare class Callable<T> {
private _target;
private _method?;
private _isStatic;
constructor(target: Instantiable<T> | Instance<T>, method?: string, isStatic?: boolean);
readonly target: Instantiable<T> | Instance<T>;
readonly method: string | undefined;
readonly isStatic: boolean;
asArray(): [Instantiable<T> | Instance<T>, string | undefined, boolean];
call(args: any[]): any;
}
export default Callable;
instead of
import { Instantiable, Instance } from '../Support/types';
declare class Callable<T> {
private _target;
private _method?;
private _isStatic;
constructor(target: Instantiable<T> | Instance<T>, method?: string, isStatic?: boolean);
readonly target: Instantiable<T> | Instance<T>;
readonly method: string | undefined;
readonly isStatic: boolean;
asArray(): [Instantiable<T> | Instance<T>, string | undefined, boolean];
call(args: any[]): any;
}
export default Callable;
My tsconfig.json, rollup.config.js files and src folder are located at the same (top) level.
Versions
- typescript: 3.2.2
- rollup: 0.68.0
- rollup-plugin-typescript2: 0.18.1
rollup.config.js
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import alias from 'rollup-plugin-alias';
import sourceMaps from 'rollup-plugin-sourcemaps';
import typescript from 'rollup-plugin-typescript2';
import {eslint} from 'rollup-plugin-eslint';
import {terser} from 'rollup-plugin-terser';
import pkg from './package.json';
export default {
input: 'src/index.ts',
output: {file: pkg.module, format: 'es', sourcemap: true},
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
],
watch: {
include: 'src/**'
},
plugins: [
eslint(),
resolve(),
commonjs(),
alias({
resolve: ['.ts'],
'@src': path.resolve(__dirname, './src')
}),
typescript({
typescript: require('typescript'),
rollupCommonJSResolveHack: true
}),
sourceMaps(),
terser()
]
};
tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@src/*": ["src/*"]
},
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"target": "es6",
"module": "es6",
"lib": ["es5", "es6", "es7", "dom"],
"removeComments": true,
"strict": true,
"sourceMap": true,
"declaration": true,
"declarationDir": "./dist",
"outDir": "./dist",
"suppressImplicitAnyIndexErrors": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"dist"
]
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
Another way is try to configure rollup-plugin-typescript2 with typescript: ttypescript and tsconfig.json > compilerOptions >
"plugins": [{ "transform": "typescript-transform-paths" }]