项目作者: Vmlweb

项目描述 :
Generates bundled Webpack Typescript declaration from exports.
高级语言: TypeScript
项目地址: git://github.com/Vmlweb/TS-Loader-Declaration.git
创建时间: 2017-03-22T17:03:36Z
项目社区:https://github.com/Vmlweb/TS-Loader-Declaration

开源协议:MIT License

下载


TS Loader Decleration

Generates bundled Webpack Typescript declarations from exports.

Inspired by declaration-bundler-webpack-plugin.

Installation

You can grab the latest version via NPM.

  1. npm install --save-dev ts-loader-decleration

Configuration

First ensure declaration: true is set in your tsconfig.json for declaration files to be generated.

Finally include the plugin in your Webpack configuration.

  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const JavaScriptObfuscator = require('webpack-obfuscator')
  4. const nodeExternals = require('webpack-node-externals')
  5. const { TSDeclerationsPlugin } = require('ts-loader-decleration')
  6. module.exports = {
  7. entry: {
  8. main: './src/index.ts',
  9. other: './src/other.ts'
  10. },
  11. target: 'node',
  12. resolve: {
  13. extensions: ['.ts', '.js']
  14. },
  15. externals: [
  16. nodeExternals()
  17. ],
  18. output: {
  19. filename: './index.js',
  20. libraryTarget: "commonjs"
  21. },
  22. plugins: [
  23. new TSDeclerationsPlugin({
  24. main: 'main'
  25. }),
  26. new webpack.optimize.UglifyJsPlugin(),
  27. new JavaScriptObfuscator({
  28. disableConsoleOutput: false
  29. }),
  30. ],
  31. module: {
  32. rules: [{
  33. test: /\.ts$/,
  34. loader: 'ts-loader',
  35. exclude: /(node_modules|bower_components)/
  36. }]
  37. }
  38. }

Only modules exported from your entry file will be included in the bundled declaration.

Awesome Typescript Loader

When using AWS there is an issue where imports will not be included in the declaration bundle unless it has been used literally. There is a loader included to patch this issue.

  1. {
  2. test: /\.ts$/,
  3. use: [{
  4. loader: 'awesome-typescript-loader',
  5. query: {
  6. declaration: true,
  7. //...
  8. }
  9. }, {
  10. loader: 'ts-loader-decleration'
  11. }]
  12. }