Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use root correctly? #59

Closed
hatton opened this issue Mar 12, 2022 · 3 comments
Closed

How to use root correctly? #59

hatton opened this issue Mar 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@hatton
Copy link

hatton commented Mar 12, 2022

Thanks for building this and sharing it!

My directory structure looks like this

My-Component/
    dist/
    lib/
    some-other-stuff/
    tsconfig.json

My vitejs build options are

 build: {
    lib: {
      entry: path.resolve(__dirname, 'lib/index.ts'),
      name: 'my-component',
      fileName: (format) => `my-component.${format}.js`,
    }
  },

If I use the plugin with the default options, vite-plugin-dts creates the files:

dist/
    lib/
        <stuff>.d.ts

That's good. But what I want to achieve is

dist/
    typings/
        <stuff>.d.ts

So I tried this

dts({
      root: 'lib',
      outputDir: 'dist/typings',
      tsConfigFilePath: '../tsconfig.json',
    }),

This runs without any errors:

[vite:dts] Start generate declaration files...
[vite:dts] Declaration files built in 5776ms.

However, now my dist directory does contain any output from the plugin. Setting logDiagnostics:true does not cause the plugin to tell me what it is doing or where it is putting the files.

So my question is, how do I set the options so that I can get the output structure I need?
Thanks!

@qmhc
Copy link
Owner

qmhc commented Mar 13, 2022

root option is using for monorepo in some cases, not necessary to change it usually.

Is your vite.config.ts in 'lib' dir ?
(it would be better for vite.config.ts and tsconfig.json in the same dir, defaults in root)

Normally you set outputDir: 'dist/typings', you will get like following paths after building:

{root}/dist/typings/lib/<stuff>.d.ts

And the type entry is the file with the same name as lib.entry: {root}/dist/typings/lib/index.d.ts

You can set "types": "dist/typings/lib/index.d.ts" in package.json to make it effective.

It's helpful that you can provide a reproductive repo.

@guoyunhe
Copy link

Same issue here. I am using Vite in a Node.js script, so here is no vite.config.ts in the library repo.

The actual output is:

dist
├── index.cjs.js
├── index.esm.js
├── index.umd.js
├── src
|   ├── Button.d.ts
|   └── index.d.ts
└── style.css

The dist/src folder is not necessary.

Expected output should be:

dist
├── index.cjs.js
├── index.esm.js
├── Button.d.ts
├── index.d.ts
├── index.umd.js
└── style.css

@qmhc qmhc closed this as completed in c939e35 Mar 22, 2022
@qmhc qmhc added the enhancement New feature or request label Mar 22, 2022
@qmhc
Copy link
Owner

qmhc commented Mar 22, 2022

Currently you can use entryRoot option to specify a entry root, the output relative paths will be calculated according to it, and it will be auto calculated as the smallest public path of all files if it is not set.

expect(
  queryPublicPath(['E:\\project\\src\\lib\\a.d.ts', 'E:\\project\\src\\lib\\b.d.ts'])
).toBe('E:\\project\\src\\lib')

// outputs: 'dist/a.d.ts' and 'dist/b.d.ts'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants