Skip to content

Commit

Permalink
chore: use lower build target (#615)
Browse files Browse the repository at this point in the history
* chore: use lower target

* chore: move code highlight config to nextra

* chore: changeset

* fix: make cusdis a component
  • Loading branch information
promer94 committed Jul 31, 2022
1 parent 6a4a593 commit 4157b71
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-weeks-judge.md
@@ -0,0 +1,5 @@
---
'nextra-theme-blog': patch
---

fix: make cusdis a component
7 changes: 7 additions & 0 deletions .changeset/silly-suns-sort.md
@@ -0,0 +1,7 @@
---
'nextra': patch
'nextra-theme-blog': patch
'nextra-theme-docs': patch
---

set lower build target and share code highlight theme through nextra
36 changes: 30 additions & 6 deletions examples/docs/src/pages/get-started.mdx
Expand Up @@ -16,17 +16,41 @@ Nextra works like a Next.js plugin, and it accepts a theme config (layout) to re
1. Install Next.js, Nextra and React

<Nextra.Tabs items={['npm', 'yarn', 'pnpm']} defaultIndex={1}>
<Nextra.Tab>```bash npm i react react-dom next nextra ```</Nextra.Tab>
<Nextra.Tab>```bash yarn add react react-dom next nextra ```</Nextra.Tab>
<Nextra.Tab>```bash pnpm i react react-dom next nextra ```</Nextra.Tab>
<Nextra.Tab>
```bash
npm i react react-dom next nextra
```
</Nextra.Tab>
<Nextra.Tab>
```bash
yarn add react react-dom next nextra
```
</Nextra.Tab>
<Nextra.Tab>
```bash
pnpm i react react-dom next nextra
```
</Nextra.Tab>
</Nextra.Tabs>

2. Install the docs theme

<Nextra.Tabs items={['npm', 'yarn', 'pnpm']} defaultIndex={1}>
<Nextra.Tab>```bash npm i nextra-theme-docs ```</Nextra.Tab>
<Nextra.Tab>```bash yarn add nextra-theme-docs ```</Nextra.Tab>
<Nextra.Tab>```bash pnpm i nextra-theme-docs ```</Nextra.Tab>
<Nextra.Tab>
```bash
npm i nextra-theme-docs
```
</Nextra.Tab>
<Nextra.Tab>
```bash
yarn add nextra-theme-docs
```
</Nextra.Tab>
<Nextra.Tab>
```bash
pnpm i nextra-theme-docs
```
</Nextra.Tab>
</Nextra.Tabs>

3. Create the following Next.js config and theme config under the root directory:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -19,12 +19,12 @@
},
"devDependencies": {
"@changesets/cli": "^2.24.1",
"@edge-runtime/vm": "1.1.0-beta.19",
"@edge-runtime/vm": "1.1.0-beta.23",
"postcss-import": "^14.1.0",
"prettier": "^2.7.1",
"prettier-plugin-tailwindcss": "^0.1.13",
"rimraf": "^3.0.2",
"turbo": "^1.3.4",
"turbo": "^1.4.0",
"typescript": "^4.7.4"
},
"prettier": {
Expand Down
11 changes: 11 additions & 0 deletions packages/nextra-theme-blog/package.json
Expand Up @@ -11,11 +11,22 @@
],
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"cusdis": [
"./dist/cusdis.d.ts"
]
}
},
"exports": {
"./style.css": "./style.css",
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./cusdis": {
"import": "./dist/cusdis.js",
"types": "./dist/cusdis.d.ts"
}
},
"scripts": {
Expand Down
3 changes: 1 addition & 2 deletions packages/nextra-theme-blog/src/article-layout.tsx
Expand Up @@ -3,7 +3,6 @@ import Meta from './meta'
import MDXTheme from './mdx-theme'
import { useBlogContext } from './blog-context'
import { BasicLayout } from './basic-layout'
import { Comments } from './cusdis'
import { getParent } from './utils/parent'

export const ArticleLayout = ({ children }: { children: ReactNode }) => {
Expand All @@ -15,7 +14,7 @@ export const ArticleLayout = ({ children }: { children: ReactNode }) => {
<MDXTheme>
{children}
{config.postFooter}
<Comments></Comments>
{config.comments}
</MDXTheme>
</BasicLayout>
)
Expand Down
4 changes: 3 additions & 1 deletion packages/nextra-theme-blog/src/cusdis.tsx
Expand Up @@ -11,7 +11,7 @@ const Cusdis = dynamic(
{ ssr: false }
) as typeof ReactCusdis

export const Comments = () => {
const Comments = () => {
const { config, opts } = useBlogContext()
const router = useRouter()
const { pageTitle } = getTitle({ opts, config })
Expand All @@ -33,3 +33,5 @@ export const Comments = () => {
/>
) : null
}

export default Comments
8 changes: 5 additions & 3 deletions packages/nextra-theme-blog/src/styles.css
@@ -1,8 +1,8 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import '../../nextra-theme-docs/src/css/variables.css';
@import '../../nextra-theme-docs/src/css/code-blocks.css';
@import 'nextra/code-highlighting/variables.css';
@import 'nextra/code-highlighting/code-blocks.css';

body {
@apply px-4;
Expand All @@ -21,11 +21,13 @@ h1 {
}

.prose code {

&:before,
&:after {
@apply hidden;
}

.line {
@apply font-normal;
}
}
}
2 changes: 2 additions & 0 deletions packages/nextra-theme-blog/src/types.ts
@@ -1,4 +1,5 @@
import { PageOpts } from 'nextra'
import React from 'react'

export interface NextraBlogTheme {
readMore?: string
Expand All @@ -22,6 +23,7 @@ export interface NextraBlogTheme {
url: string
name: string
}[]
comments?: React.ReactNode
}

export interface BlogPageOpts extends PageOpts {
Expand Down
3 changes: 2 additions & 1 deletion packages/nextra-theme-blog/tsconfig.json
Expand Up @@ -10,7 +10,8 @@
"allowJs": true,
"jsx": "react",
"moduleResolution": "Node",
"types": ["vitest/globals"]
"types": ["vitest/globals"],
"resolveJsonModule": true
},
"include": ["."]
}
7 changes: 4 additions & 3 deletions packages/nextra-theme-blog/tsup.config.ts
@@ -1,15 +1,16 @@
import { defineConfig } from 'tsup'

import tsconfig from './tsconfig.json'
function outExtension() {
return {
js: `.js`
}
}

export default defineConfig({
entry: ['src/index.tsx'],
entry: ['src/index.tsx', "src/cusdis.tsx"],
format: 'esm',
dts: true,
name: 'nextra-theme-blog',
outExtension
outExtension,
target: tsconfig.compilerOptions.target
})
4 changes: 2 additions & 2 deletions packages/nextra-theme-docs/src/css/styles.css
@@ -1,8 +1,8 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import './variables.css';
@import './code-blocks.css';
@import 'nextra/code-highlighting/variables.css';
@import 'nextra/code-highlighting/code-blocks.css';

:root {
--nextra-primary-hue: 212deg;
Expand Down
3 changes: 2 additions & 1 deletion packages/nextra-theme-docs/tsconfig.json
Expand Up @@ -10,6 +10,7 @@
"allowJs": true,
"jsx": "react",
"moduleResolution": "Node",
"types": ["vitest/globals"]
"types": ["vitest/globals"],
"resolveJsonModule": true
}
}
33 changes: 17 additions & 16 deletions packages/nextra-theme-docs/tsup.config.ts
@@ -1,37 +1,38 @@
import { defineConfig } from 'tsup'
import tsconfig from './tsconfig.json'

function outExtension() {
return {
js: `.js`
}
}
const { compilerOptions: { target } } = tsconfig

const sharedConfig = defineConfig({
format: 'esm',
dts: true,
outExtension,
target
})
export default defineConfig([
{
entry: ['src/bleed.tsx', 'src/callout.tsx'],
format: 'esm',
outExtension,
dts: true,
name: 'nextra-theme-docs/components'
name: 'nextra-theme-docs/components',
...sharedConfig
},
{
name: 'nextra-theme-docs',
entry: ['src/index.tsx'],
format: 'esm',
outExtension,
dts: true,
name: 'nextra-theme-docs'
...sharedConfig
},
{
name: 'nextra-theme-docs/tabs',
entry: ['src/components/tabs.tsx'],
format: 'esm',
outExtension,
dts: true,
name: 'nextra-theme-docs/tabs'
...sharedConfig
},
{
name: 'nextra-theme-docs/collapse',
entry: ['src/components/collapse.tsx'],
format: 'esm',
outExtension,
dts: true,
name: 'nextra-theme-docs/collapse'
...sharedConfig
}
])
3 changes: 2 additions & 1 deletion packages/nextra/package.json
Expand Up @@ -5,7 +5,8 @@
"files": [
"dist/*",
"icons/*",
"loader.js"
"loader.js",
"code-highlighting/*"
],
"types": "./dist/types.d.ts",
"main": "./dist/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/nextra/tsconfig.json
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ESNext",
"target": "es2016",
"module": "ESNext",
"declaration": true,
"noEmit": true,
Expand All @@ -10,7 +10,7 @@
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["vitest/globals"]
"types": ["vitest/globals"],
"resolveJsonModule": true
}
}
24 changes: 16 additions & 8 deletions packages/nextra/tsup.config.ts
@@ -1,35 +1,43 @@
import { defineConfig } from 'tsup'
import tsconfig from './tsconfig.json'
const { compilerOptions: { target } } = tsconfig

export default defineConfig([
{
name: 'nextra',
entry: ['src/index.js'],
format: 'cjs',
name: 'nextra',
dts: false
dts: false,
target
},
{
name: 'nextra-utils',
entry: ['src/ssg.ts', 'src/locales.ts', 'src/context.ts'],
format: 'cjs',
name: 'nextra-utils',
external: ['next/server'],
dts: true
dts: true,
target
},
{
name: 'nextra-loader',
entry: ['src/loader.ts'],
format: 'esm',
name: 'nextra-loader',
dts: true
dts: true,
target
},
{
entry: ['src/compile.ts'],
format: 'esm',
name: 'nextra-mdx-compiler',
dts: true
dts: true,
target
},
{
entry: ['src/icons.ts'],
name: 'nextra-icons',
format: 'esm',
dts: true
dts: true,
target
},
{
entry: ['src/types.ts'],
Expand Down

0 comments on commit 4157b71

Please sign in to comment.