我目前正在使用“gulp”来生成我的包的定义文件,如下所示:
dtsGenerator.default({
name: 'ngFramework',
project: './',
out: './Typings/raw/index.d.ts'
});
但是,我正在迁移到 webpack,并且我想找到一种方法来做到这一点。我尝试了“tsconfig”中的“声明”标志,但它只是为每个“ts”文件创建定义文件,这不是我想要的(我想要捆绑包的定义文件)。
我尝试了“dtsbundler-webpack-plugin”,但无法使其按预期工作。如果没有“tsconfig”的“声明”标志,生成的文件是“0字节”,有了它,我有很多错误。
你应该使用DTS 捆绑包 https://github.com/TypeStrong/dts-bundle用WebPack生成bundle。您应该将声明标志保留为 true 并尝试以下操作:
General
var path = require('path');
var rootDir = path.resolve(__dirname);
编写简单的插件
function DtsBundlePlugin() {}
DtsBundlePlugin.prototype.apply = function (compiler) {
compiler.plugin('done', function () {
var dts = require('dts-bundle');
dts.bundle({
name: 'your-lib-name',
main: rootDir + '/build/types/**/*.d.ts',
out: rootDir + '/build/index.d.ts',
removeSource: true,
outputAsModuleFolder: true
});
});
};
更多信息可以找到在 Vladimir Tolstikov 的这篇博文中 https://medium.com/@vladimirtolstikov/how-to-merge-d-ts-typings-with-dts-bundle-and-webpack-e8903d699576.
登记
plugins: [
new DtsBundlePlugin()
]
我已成功捆绑打字,但与我的源代码相关的捆绑代码遇到了一些问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)