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

feat: migrate to ESM (#645) #659

Merged
merged 11 commits into from May 27, 2022
Merged

feat: migrate to ESM (#645) #659

merged 11 commits into from May 27, 2022

Conversation

antfu
Copy link
Member

@antfu antfu commented May 26, 2022

close #645

This shouldn't have much impact on the user side as Vitepress is mostly a CLI tool

Changes

  • "type": "module" and now .js are all ESM
  • Use rollup-plugin-dts instead of api-extractor for simplity
  • Use picocolors, fast-glob, simple-git-hooks and prompts to align with vite
  • Bumpped engine to >=14.6.0 to match with Vite

@antfu antfu requested review from kiaking and patak-dev May 26, 2022 04:44
"compilerOptions": {
"baseUrl": ".",
"outDir": "../../dist/client",
"target": "esnext",
"module": "esnext",
"declaration": true,
"declarationDir": "../../dist/client-types",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be client instead of client-types?

Suggested change
"declarationDir": "../../dist/client-types",
"declarationDir": "../../dist/client",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait not really, we need client-types in rollup config... However, this raises

[!] (plugin cleanup) Error: ENOENT: no such file or directory, stat '/Users/kia/Code/vitepress-next/dist/client-types'

When running pnpm run docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this is happening because on dev command, client build executes, and then node build (rollup) executes in parallel and client-types folder gets deleted becaue of cleanup hook in rollup config. So we should first check for the folder existense and then perform delete on the folder I guess.

So maybe we just do this?

// rollup.config.ts
plugins: [
  dts(),
  {
    name: 'cleanup',
    async closeBundle() {
      try {
        await fs.rm(r('dist/client-types'), { recursive: true })
      } catch {}
    }
  }
]

@kiaking kiaking self-requested a review May 26, 2022 10:44
@kiaking
Copy link
Member

kiaking commented May 26, 2022

@antfu Currently, because we only have es build, the consumer of VitePress have to define "type": "module".

Maybe we need cjs build as well? Since if someone is building none type module lib and if they want to create docs with VitePress, are they doomed? 🤔

@kiaking
Copy link
Member

kiaking commented May 27, 2022

I think I'll add cjs support. Tested locally with Vite and it will work with/without "type": "module".

@kiaking kiaking mentioned this pull request May 27, 2022
@kiaking
Copy link
Member

kiaking commented May 27, 2022

Opened PR that targets this PR at #666.

@patak-dev
Copy link
Member

This is awesome! Related vitejs/vite#8348 (comment). I think we should be able to test VitePress with the new ESM SSR build after this PR is merged.

@kiaking
Copy link
Member

kiaking commented May 27, 2022

Cool 👀 I'm resolving conflict now and will merge it soon 👍

@kiaking kiaking changed the title feat: migrate to ESM feat: migrate to ESM (#645) May 27, 2022
@kiaking kiaking merged commit a0f81c9 into next-theme May 27, 2022
@kiaking kiaking deleted the feat/esm branch May 27, 2022 12:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants