mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
write out DTS file structure
This commit is contained in:
parent
a355b88b04
commit
b948b49d75
@ -71,7 +71,12 @@ Plugin takes following options:
|
||||
|
||||
* `rollupCommonJSResolveHack`: false
|
||||
|
||||
On windows typescript resolver favors POSIX path, while commonjs plugin (and maybe others?) uses native path as module id. This can result in `namedExports` being ignored if rollup happened to use typescript's resolution. Set to true to pass resolved module path through `resolve()` to match up with `rollup-plugin-commonjs`.
|
||||
On windows typescript resolver favors POSIX path, while commonjs plugin (and maybe others?) uses native path as module id. This can result in `namedExports` being ignored if rollup happened to use typescript's resolution. Set to true to pass resolved module path through `resolve()` to match up with `rollup-plugin-commonjs`.
|
||||
|
||||
### Declarations
|
||||
|
||||
This plugin respects `declaration: true` in your `tsconfig.json` file. When set, it will emit `*.d.ts` files for your bundle. The resulting file(s) can then be used with the `types`
|
||||
property in your `package.json` file as described [here](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).
|
||||
|
||||
### Watch mode
|
||||
|
||||
|
||||
1150
dist/rollup-plugin-typescript2.cjs.js
vendored
1150
dist/rollup-plugin-typescript2.cjs.js
vendored
File diff suppressed because it is too large
Load Diff
1150
dist/rollup-plugin-typescript2.es.js
vendored
1150
dist/rollup-plugin-typescript2.es.js
vendored
File diff suppressed because it is too large
Load Diff
14
src/index.ts
14
src/index.ts
@ -152,6 +152,8 @@ export default function typescript(options: IOptions)
|
||||
|
||||
let noErrors = true;
|
||||
|
||||
const declarations: ts.OutputFile[] = [];
|
||||
|
||||
// printing compiler option errors
|
||||
if (options.check)
|
||||
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
|
||||
@ -249,10 +251,12 @@ export default function typescript(options: IOptions)
|
||||
|
||||
const transpiled = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".js") );
|
||||
const map = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".map") );
|
||||
const dts = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".d.ts"));
|
||||
|
||||
return {
|
||||
code: transpiled ? transpiled.text : undefined,
|
||||
map: map ? JSON.parse(map.text) : { mappings: "" },
|
||||
dts,
|
||||
};
|
||||
});
|
||||
|
||||
@ -275,6 +279,10 @@ export default function typescript(options: IOptions)
|
||||
printDiagnostics(contextWrapper, diagnostics);
|
||||
}
|
||||
|
||||
if (result && result.dts) {
|
||||
declarations.push(result.dts);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
@ -311,5 +319,11 @@ export default function typescript(options: IOptions)
|
||||
|
||||
round++;
|
||||
},
|
||||
|
||||
onwrite() {
|
||||
declarations.forEach(({ name, text, writeByteOrderMark }) => {
|
||||
ts.sys.writeFile(name, text, writeByteOrderMark);
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ export interface ICode
|
||||
{
|
||||
code: string | undefined;
|
||||
map: string | undefined;
|
||||
dts?: ts.OutputFile | undefined;
|
||||
}
|
||||
|
||||
interface INodeLabel
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user