From 9df8adb53e2ed4ebcfa80c2df2af12b2207c7ee7 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:51:48 +0530 Subject: [PATCH] chore(build)!: drop cjs api (#2737) --- docs/guide/getting-started.md | 6 ++++++ docs/reference/site-config.md | 2 +- package.json | 3 +-- rollup.config.ts | 20 -------------------- src/node/config.ts | 2 +- theme-without-fonts.d.ts | 4 ++-- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index d1714f28..acb29568 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -47,6 +47,12 @@ If using PNPM, you will notice a missing peer warning for `@docsearch/js`. This ::: +::: tip NOTE + +VitePress is an ESM-only package. Don't use `require()` to import it, and make sure your nearest `package.json` contains `"type": "module"`, or change the file extension of your relevant files like `.vitepress/config.js` to `.mjs`/`.mts`. Refer [Vite's troubleshooting guide](http://vitejs.dev/guide/troubleshooting.html#this-package-is-esm-only) for more details. Also, inside async CJS contexts, you can use `await import('vitepress')` instead. + +::: + ### Setup Wizard VitePress ships with a command line setup wizard that will help you scaffold a basic project. After installation, start the wizard by running: diff --git a/docs/reference/site-config.md b/docs/reference/site-config.md index ee16a0cd..1bc97b92 100644 --- a/docs/reference/site-config.md +++ b/docs/reference/site-config.md @@ -10,7 +10,7 @@ Site config is where you can define the global settings of the site. App config ### Config Resolution -The config file is always resolved from `/.vitepress/config.[ext]`, where `` is your VitePress [project root](../guide/routing#root-and-source-directory), and `[ext]` is one of the supported file extensions. TypeScript is supported out of the box. Supported extensions include `.js`, `.ts`, `.cjs`, `.mjs`, `.cts`, and `.mts`. +The config file is always resolved from `/.vitepress/config.[ext]`, where `` is your VitePress [project root](../guide/routing#root-and-source-directory), and `[ext]` is one of the supported file extensions. TypeScript is supported out of the box. Supported extensions include `.js`, `.ts`, `.mjs`, and `.mts`. It is recommended to use ES modules syntax in config files. The config file should default export an object: diff --git a/package.json b/package.json index 2a14c13f..e90a7792 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,7 @@ "exports": { ".": { "types": "./types/index.d.ts", - "import": "./dist/node/index.js", - "require": "./dist/node-cjs/index.cjs" + "default": "./dist/node/index.js" }, "./dist/*": "./dist/*", "./package.json": "./package.json", diff --git a/rollup.config.ts b/rollup.config.ts index 1a5ec684..9c43ac3d 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -62,21 +62,6 @@ const esmBuild: RollupOptions = { } } -const cjsBuild: RollupOptions = { - input: [r('src/node/index.ts'), r('src/node/cli.ts')], - output: { - format: 'cjs', - dir: r('dist/node-cjs'), - entryFileNames: `[name].cjs`, - chunkFileNames: 'serve-[hash].cjs' - }, - external, - plugins, - onwarn(warning, warn) { - if (warning.code !== 'EVAL') warn(warning) - } -} - const nodeTypes: RollupOptions = { input: r('src/node/index.ts'), output: { @@ -110,11 +95,6 @@ const clientTypes: RollupOptions = { const config = defineConfig([]) config.push(esmBuild) - -if (PROD) { - config.push(cjsBuild) -} - config.push(nodeTypes) config.push(clientTypes) diff --git a/src/node/config.ts b/src/node/config.ts index a6591adf..6ca58653 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -138,7 +138,7 @@ export async function resolveConfig( return config } -const supportedConfigExtensions = ['js', 'ts', 'cjs', 'mjs', 'cts', 'mts'] +const supportedConfigExtensions = ['js', 'ts', 'mjs', 'mts'] export async function resolveUserConfig( root: string, diff --git a/theme-without-fonts.d.ts b/theme-without-fonts.d.ts index 7a71fe6d..531dd12e 100644 --- a/theme-without-fonts.d.ts +++ b/theme-without-fonts.d.ts @@ -1,2 +1,2 @@ -export * from './theme' -export { default } from './theme' +export * from './theme.js' +export { default } from './theme.js'