DEV Community

Discussion on: How to build a simple SDK on TypeScript

Collapse
 
cadrogui profile image
Mikel Carozzi • Edited

Great article, thanks for share. the article does not cover the build of a single file sdk, here are some inputs.

a webpack.config.js file

const path = require('path');

module.exports = {
  mode: "production",
  devtool: "inline-source-map",
  entry: {
    main: "./index.ts",
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: "sdk-file.js",
    library: 'name-of-the-main-class',
    libraryTarget: "umd",
    libraryExport: "default"
  },
  resolve: {
    extensions: [".ts", ".tsx", ".js"],
  },
  module: {
    rules: [
      { 
        test: /\.tsx?$/,
        loader: "ts-loader"
      }
    ]
  }
};
Enter fullscreen mode Exit fullscreen mode

install ts-loader, webpack-cli and npm script for build
build: "webpack"

this work for me and let me build a sdk in a single file.

in the html file dont forget to use

<script type="module"></script>
Enter fullscreen mode Exit fullscreen mode

for include the js file and for the code

Collapse
 
labeebshareef profile image
labeebshareef

getting error:
ReferenceError: FormData is not defined
when added build to testing app
created a package.json file in the dist folder

repo: github.com/labeebshareef/typescrip...