HJinPeng / vite-plugin-vue-css-module

css-module syntactic sugar for vue3
MIT License
7 stars 2 forks source link

types are published incorrectly #4

Closed IlyaSemenov closed 1 year ago

IlyaSemenov commented 1 year ago

With 1.3.1, what is installed to node_modules with npm install is:

image

dist/types/index.d.ts has:

import type { Plugin } from 'vite';
import type { PluginOptions } from './utils/types';
export default function vueCssModule(userOptions?: Partial<PluginOptions>): Plugin;

Clearly, this is wrong. There is no './utils/types' in the distribution to import from, and the actual types are non-functional. As a result, there is no type check when calling the plugin:

vueCssModule({ attrName: "mclass", blabla: true }) // Works, but error expected: no such property "blabla".

I tried running npm run build in the latest master, but that generated even stranger result:

dist
dist/types
dist/types/test
dist/types/test/object-array.spec.d.ts
dist/types/test/array-array.spec.d.ts
...
dist/types/test/array-object.spec.d.ts
dist/types/vitest.config.d.ts
dist/types/src
dist/types/src/utils
dist/types/src/utils/parseVue.d.ts
dist/types/src/utils/types.d.ts
dist/types/src/utils/tool.d.ts
dist/types/src/utils/parseHtml.d.ts
dist/types/src/utils/parsePug.d.ts
dist/types/src/index.d.ts

So there is even no dist/types/index.d.ts, but instead a whole bunch of useless .d.ts files.


I propose to replace rollup with tsup which is a wrapper around rollup for creating library bundles, with very reasonable and unobtrusive defaults. Let me know what you think? Here's the tsup.config.js I'm using for my libraries:

import { defineConfig } from "tsup"

export default defineConfig({
  clean: true,
  entry: ["src/index.ts"],
  format: ["cjs", "esm"],
  sourcemap: true,
  dts: true,
})

Then simply run tsup and it generates a fully working bundle at dist/, including proper type bindings.

HJinPeng commented 1 year ago

Originally, I used declaration in tsconfig.json to generate the declaration file, which caused the problem. In tag branch v1.3.3, I turned off declaration and used rollup-plugin-dts to generate index.d.ts, and it worked normally. The tsup you recommended is indeed very convenient and easy to use, and it is adopted in v1.3.4. Thanks