JSPM

ts-loader-decleration-webpack5

0.11.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q22391F
  • License MIT

Enables bundled Webpack Typescript declarations from exports.

Package Exports

  • ts-loader-decleration-webpack5

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-loader-decleration-webpack5) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.

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.

const path = require('path')
const webpack = require('webpack')
const JavaScriptObfuscator = require('webpack-obfuscator')
const nodeExternals = require('webpack-node-externals')
const { TSDeclerationsPlugin } = require('ts-loader-decleration')

module.exports = {
    entry: {
        main: './src/index.ts',
        other: './src/other.ts'
    },
    target: 'node',
    resolve: {
        extensions: ['.ts', '.js']
    },
    externals: [
        nodeExternals()
    ],
    output: {
        filename: './index.js',
        libraryTarget: "commonjs"
    },
    plugins: [
        new TSDeclerationsPlugin({
            main: 'main'
        }),
        new webpack.optimize.UglifyJsPlugin(),
        new JavaScriptObfuscator({
            disableConsoleOutput: false
        }),
    ],
    module: {
        rules: [{
            test: /\.ts$/,
            loader: 'ts-loader',
            exclude: /(node_modules|bower_components)/
        }]
    }
}

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.

{
    test: /\.ts$/,
    use: [{
        loader: 'awesome-typescript-loader',
        query: {
            declaration: true,
            //...
        }
    }, {
        loader: 'ts-loader-decleration'
    }]
}