guoyunhe / swc-minify-webpack-plugin

A faster minimizer for webpack based on swc.minify()
Apache License 2.0
7 stars 1 forks source link

Fix generated type declarations #2

Closed sirreal closed 1 year ago

sirreal commented 1 year ago

Fix the generated type declarations.

By using TypeScript's special export = we're able to author source that mostly looks like ESM but generates our desired declaration and js output.

The published type declarations are currently export {}, which makes it hard to use this package in typechecked files.

After this change, the generated JS file is mostly the same, but the declaration file has the expected output:

import { JsMinifyOptions } from '@swc/core';
import webpack from 'webpack';
declare class SwcMinifyWebpackPlugin {
    private readonly options;
    constructor(options?: JsMinifyOptions);
    apply(compiler: webpack.Compiler): void;
    private transformAssets;
    private processAssets;
}
export = SwcMinifyWebpackPlugin;

Another change that may be helpful to use a shared tsconfig designed for node, for example:

https://github.com/tsconfig/bases#node-lts--strictest-tsconfigjson

That will likely improve the build result and save generating compatibility code that's not necessary for targeting Node.

I'd be happy to push that here or in another PR.

guoyunhe commented 1 year ago

Released in 1.1.1

sirreal commented 1 year ago

The new releases have the same problem, the published declarations are an empty export. At 1e03fee111c36abd05646d6b99cc31536b053130 (merge commit) this generated the expected declarations.