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

Fix bundler #1

Closed
colgin opened this issue May 19, 2021 · 6 comments
Closed

Fix bundler #1

colgin opened this issue May 19, 2021 · 6 comments

Comments

@colgin
Copy link

colgin commented May 19, 2021

Remove the plugins in rollupOptions, and declare it as a "vitePlugin", it works.

import vue from '@vitejs/plugin-vue'
import rollupTs from 'rollup-plugin-typescript2'
import path from 'path'
import type { ConfigEnv, UserConfig } from 'vite'

const resolvePath = (p) => path.resolve(__dirname, p)

// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => ({
  plugins: [
    vue(),
    {
      ...rollupTs({
        check: true,
        tsconfig: path.resolve(__dirname, `tsconfig.json`), // your tsconfig.json path
        tsconfigOverride: {
          compilerOptions: {
            sourceMap: false,
            declaration: true,
            declarationMap: false,
          },
        },
      }),
      enforce: 'pre',
    },
  ],
  build: {
    minify: mode === 'production',
    lib: {
      entry: path.resolve(__dirname, 'src/index.ts'),
      name: 'AButton',
    },
    rollupOptions: {
      // Maybe you don't need to declare input in rollupOptions, because you have declared it in lib
      // input: resolvePath('src/index.ts'),
      // plugins: [
      //   rollupTs({
      //     check: true,
      //     tsconfig: path.resolve(__dirname, `tsconfig.json`), // your tsconfig.json path
      //     // tsconfigOverride: {
      //     //   compilerOptions: {
      //     //     sourceMap: false,
      //     //     declaration: true,
      //     //     declarationMap: false,
      //     //   },
      //     // },
      //   }),
      // ],
      external: ['vue'],
      output: [
        {
          format: 'cjs',
          dir: undefined,
          file: './dist/index.js',
        },
        {
          format: 'es',
          dir: undefined,
          file: './dist/index.mjs',
        },
      ],
    },
  },
})
@harrytran998
Copy link
Owner

@colgin You can pull this code and run! I tried and still not work 😅

@colgin
Copy link
Author

colgin commented May 20, 2021

I pull the code, and run

yarn
yarn build

it looks good.
截屏2021-05-20 上午9 27 03

if you get error, you can post a image to show what the error is

@colgin
Copy link
Author

colgin commented May 20, 2021

Hi, there, rollup-plugin-typescript2 doesn't work well with pnpm, issue.
use yarn or npm, everything works well.

@harrytran998
Copy link
Owner

Hi, there, rollup-plugin-typescript2 doesn't work well with pnpm, issue.
use yarn or npm, everything works well.

Oh ... Thank you so much <3! LOL I don't think it's issue of pnpm :(

@harrytran998
Copy link
Owner

Hi, there, rollup-plugin-typescript2 doesn't work well with pnpm, issue.
use yarn or npm, everything works well.

Btw, can I ask you a question? How do you know this is the problem with the plugin order of Vite?

@colgin
Copy link
Author

colgin commented May 20, 2021

It depends on how vite process the input accroding your configuration.
If you place the tsPlugin in rollupOptions.plugins, according the error, .vue file didn't produce the type file correctly, plain .ts file can produce the right type file.

So I guess plugins in rollupOptions only applied to some processed files(.vue files was translated to normal .js file without any type), after that, I spend some time to figure out if there is a way to apply tsPlugin to original file, including read the source code and doc.

Vite plugin extends rollup's plugin interface, according the doc, plugin specified enfore as 'pre' will be applied before plugin without enfore value.

btw, I don’t know if this solution will bring any side effects, in my current opinion, it is good

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

No branches or pull requests

2 participants