Skip to content

chore: 🤖 rollup jsx files #1819

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

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dev/src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import globalPackageJson from '../../package.json' with { type: 'json' }

const external = [/@milkdown/]

const libFileName = (format: string) => `index.${format}.js`

function isObject(item: unknown): item is Record<string, unknown> {
return Boolean(item && typeof item === 'object' && !Array.isArray(item))
}
Expand Down Expand Up @@ -53,7 +51,7 @@ function viteBuild(path: string, options: BuildOptions = {}): BuildOptions {
lib: {
entry: resolve(dir, 'src', 'index.ts'),
name: `milkdown_${packageDirName}`,
fileName: libFileName,
fileName: 'index',
formats: ['es'],
},
rollupOptions: {
Expand Down
3 changes: 3 additions & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
"lib",
"src"
],
"scripts": {
"build": "rollup -c"
},
"peerDependencies": {
"@codemirror/language": "^6",
"@codemirror/state": "^6",
Expand Down
68 changes: 68 additions & 0 deletions packages/components/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import esbuild from 'rollup-plugin-esbuild'

import pkg from './package.json' with { type: 'json' }

const external = [
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies || {}),
/@milkdown\/prose/,
]

const main = [
{
input: './src/index.ts',
output: {
file: 'lib/index.js',
format: 'esm',
sourcemap: true,
},
external,
plugins: [
resolve({ browser: true }),
json(),
commonjs(),
esbuild({
target: 'es6',
}),
],
},
]

function componentModule(name) {
const input = `./src/${name}/index.ts`
return [
{
input,
output: {
file: `lib/${name}/index.js`,
format: 'esm',
sourcemap: true,
},
external,
plugins: [
resolve({ browser: true }),
json(),
commonjs(),
esbuild({
target: 'es6',
}),
],
},
]
}

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
const dirs = fs.readdirSync(path.resolve(dirname, './src'))

export default () =>
dirs
.filter((x) => x !== '__internal__' && !x.includes('index'))
.flatMap(componentModule)
.concat(main)
1 change: 1 addition & 0 deletions packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment",
"jsxImportSource": "vue",
"emitDeclarationOnly": true,
"rootDir": "src",
"outDir": "lib",
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo"
Expand Down
3 changes: 0 additions & 3 deletions packages/exception/vite.config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/integrations/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
}
}
},
"scripts": {
"build": "vite build"
},
"files": [
"lib",
"src"
Expand Down
1 change: 1 addition & 0 deletions packages/integrations/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"jsx": "react",
"rootDir": "src",
"outDir": "lib",
"emitDeclarationOnly": true,
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo"
},
"include": ["src"],
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/integrations/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
}
}
},
"scripts": {
"build": "vite build"
},
"files": [
"lib",
"src"
Expand Down
7 changes: 3 additions & 4 deletions packages/integrations/vue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"jsx": "preserve",
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment",
"jsx": "react-jsx",
"jsxImportSource": "vue",
"emitDeclarationOnly": true,
"rootDir": "src",
"outDir": "lib",
"jsxImportSource": "vue",
"tsBuildInfoFile": "./lib/tsconfig.tsbuildinfo"
},
"include": ["src"],
Expand Down
10 changes: 10 additions & 0 deletions packages/integrations/vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { pluginViteConfig } from '@milkdown/dev/vite'
import vueJsx from '@vitejs/plugin-vue-jsx'

export default pluginViteConfig(import.meta.url, {
plugins: [vueJsx()],
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
})
4 changes: 2 additions & 2 deletions packages/plugins/theme-nord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
},
"main": "./src/index.ts",
"publishConfig": {
"main": "./lib/index.es.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.es.js"
"import": "./lib/index.js"
},
"./style.css": "./lib/style.css"
}
Expand Down