I am trying rollup js to build my typescript project but I don't know how to generate the definition files and how to include them automatically in the dist files.
Would anyone know how to do it ?
Here is my rollup.config.js
import typescript from "rollup-plugin-typescript";
import handlebars from "rollup-plugin-handlebars";
import babel from 'rollup-plugin-babel';
export default {
entry: 'src/generator.ts',
format: 'cjs',
plugins: [
typescript(),
handlebars(),
babel()
],
dest: 'dist/bundle.js'
};
I'm using the default ts config but that's the same with declaration=true.
edit :
Also trying using Webpack :
module.exports = {
context: __dirname + '/src',
entry: {
index: './generator'
},
output: {
path: __dirname + '/build',
publicPath: '/',
filename: 'generator.js'
},
resolve: {
root: __dirname,
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loaders: ['ts-loader'], exclude: /node_modules/ },
{ test: /\.hbs/, loaders: ['handlebars-loader'], exclude: /node_modules/ }
]
}
}
Tsconfig :
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "build"
},
"exclude": [
"node_modules",
"dist",
"build"
]
}
The generate d.ts looks like this :
import { ExportPageModel } from './models/page-model';
export declare type ExportType = 'text' | 'html';
export * from './models/page-model';
export declare namespace Generator {
function generateHtml(page: ExportPageModel): string;
function generateText(page: ExportPageModel): string;
}
But in my app using that package, it can't find the Generator...
import { ExportPageModel, Generator } from 'emlb-generator';
Generator is undefined but the auto completion works fine so I can't find where is the problem :(
Generator.generateHtml({
...
});
Highly recommend you compile using just
tsc
. Reserve rollup for final application bundling.Example
For examples checkout the build in typestyle https://github.com/typestyle/typestyle/blob/2349f847abaaddaf3de4ca83f585d293b766959e/package.json#L10