jharris4 / html-webpack-tags-plugin

lets you define html tags to inject with html-webpack-plugin
MIT License
256 stars 31 forks source link

Add TypeScript support #52

Closed tkrotoff closed 5 years ago

tkrotoff commented 5 years ago

Current type definition I use in my projects (something like types/html-webpack-tags-plugin.d.ts):

declare module 'html-webpack-tags-plugin' {
  import { Plugin } from 'webpack';

  interface Options {
    append?: boolean;
    prependExternals?: boolean;
    jsExtensions?: string | string[];
    cssExtensions?: string | string[];
    useHash?: boolean;
    addHash?: (assetPath: string, hash: string) => string;
    hash?: boolean | Function;
    usePublicPath?: boolean;
    addPublicPath?: (assetPath: string, publicPath: string) => string;
    publicPath?: boolean | string | Function;

    tags?: string | object | Array<string | object>;
    links?: string | object | Array<string | object>;
    scripts?: string | object | Array<string | object>;
    metas?: string | object | Array<string | object>;
  }

  export default class HtmlWebpackTagsPlugin extends Plugin {
    constructor(options: Options);
  }
}

Then you have autocompletion using vscode or whatever smart editor/IDE:

// webpack.config.ts
import HtmlWebpackTagsPlugin from 'html-webpack-tags-plugin';

...
new HtmlWebpackTagsPlugin({...});
...

3 solutions (see https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html):

jharris4 commented 5 years ago

Can you elaborate on what this means? Are you just looking for TypeScript types?

If so, a PR would be welcome...

jharris4 commented 5 years ago

Ok, I’m new to TypeScript but I’m curious.

Thanks for sharing your starter definition, I’ll see if I can find time to get around to adding it next week.

jharris4 commented 5 years ago

I've added the TypeScript definitions and released in 2.0.16.

@tkrotoff Can you please try out the definitions in the new version and let me know if it works for you so I can close this issue? Thanks!

tkrotoff commented 5 years ago

File types.d.ts is not part of the package: https://unpkg.com/browse/html-webpack-tags-plugin@2.0.16/

I guess you have to add types.d.ts to files inside package.json: https://docs.npmjs.com/files/package.json#files

  ...
  "files": [
    "index.js",
    "types.d.ts"
  ],
  ...
jharris4 commented 5 years ago

Oh crap! yeah I only tested locally with import HtmlWebpackTagsPlugin from "../typings.d.ts";

I'll publish another version with the file added. Sorry about that, and thanks for reporting it!

jharris4 commented 5 years ago

Published in 2.0.17. That should do the trick.

tkrotoff commented 5 years ago

It works fine, thx!