Skip to content

Commit

Permalink
fix: dts bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Dec 10, 2022
1 parent 0b924bb commit 504f8af
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 106 deletions.
2 changes: 2 additions & 0 deletions packages/kami-design/components/Markdown/parsers/katex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
simpleInlineRegex,
} from 'markdown-to-jsx'
import type { FC } from 'react'
// @ts-ignore
import { useInsertionEffect, useState } from 'react'

import { loadScript, loadStyleSheet } from '~/utils/load-script'
Expand Down Expand Up @@ -39,6 +40,7 @@ const LateX: FC<{ children: string }> = (props) => {
loadScript(
'https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-M/KaTeX/0.15.2/katex.min.js',
).then(() => {
// @ts-ignore
const html = window.katex.renderToString(children)
setHtml(html)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/kami-design/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
/// <reference types="./filetyping.d.ts" />
/// <reference types="./react-next.d.ts" />
/// <reference types="./env.d.ts" />
4 changes: 4 additions & 0 deletions packages/kami-design/filetyping.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.module.css' {
const classes: { [key: string]: string }
export default classes
}
3 changes: 3 additions & 0 deletions packages/kami-design/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="./env.d.ts" />

// export { Markdown } from './components/Markdown'
// export { Banner } from './components/Banner'
// export { Divider, DividerVertical } from './components/Divider'
Expand Down
18 changes: 10 additions & 8 deletions packages/kami-design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"exports": {
".": {
"type": "./dist/packages/kami-design/index.d.ts",
"type": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
Expand All @@ -20,7 +20,8 @@
},
"bump": {
"leading": [
"pnpm -C ./packages/kami-design run build"
"pnpm -C ./packages/kami-design run build",
"pnpm -C ./packages/kami-design run types"
],
"allowed_branches": [
"main",
Expand All @@ -29,7 +30,7 @@
],
"publish": true,
"commit_message": "chore(release): bump @mx-space/kami-design to v${NEW_VERSION}",
"tag-prefix": "@mx-space/kami-design@v"
"tag": false
},
"files": [
"dist",
Expand All @@ -43,21 +44,21 @@
"scripts": {
"prebuild": "rm -rf dist types",
"build": "rollup -c",
"types": "rm -rf types && tsc --build tsconfig.types.json && tsc-alias -p tsconfig.types.json"
"types": "rm -rf types && tsc --build tsconfig.types.json && tsc-alias -p tsconfig.types.json && dts-bundle-generator -o ./dist/index.d.ts ./index.ts --no-check --silent --project ./tsconfig.types.json"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"markdown-to-jsx": "npm:@innei/markdown-to-jsx@7.1.3-15",
"@floating-ui/react-dom": "^1.0.1",
"@formkit/auto-animate": "^1.0.0-beta.5",
"@mx-space/api-client": "^1.0.0-beta.3",
"clsx": "^1.2.1",
"css-spring": "^4.1.0",
"lodash-es": "^4.17.0",
"markdown-escape": "^2.0.0",
"markdown-to-jsx": "npm:@innei/markdown-to-jsx@7.1.3-15",
"medium-zoom": "^1.0.8",
"react-collapse": "^5.1.1",
"react-intersection-observer": "^9.4.1",
Expand All @@ -66,7 +67,6 @@
"remove-markdown": "^0.5.0"
},
"devDependencies": {
"react-use": "17.4.0",
"@babel/plugin-transform-react-jsx": "7.19.0",
"@babel/plugin-transform-typescript": "7.20.2",
"@babel/preset-react": "7.18.6",
Expand All @@ -75,14 +75,16 @@
"@rollup/plugin-node-resolve": "14.0.1",
"@rollup/plugin-typescript": "8.5.0",
"@types/react": "17.0.52",
"dts-bundle-generator": "^7.1.0",
"esbuild": "0.15.17",
"react-use": "17.4.0",
"rollup": "2.79.0",
"rollup-plugin-esbuild": "5.0.0",
"rollup-plugin-peer-deps-external": "2.2.4",
"rollup-plugin-postcss": "4.0.2",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-windicss": "1.8.8",
"typescript": "4.9.3",
"tsc-alias": "1.7.0"
"tsc-alias": "1.7.0",
"typescript": "4.9.3"
}
}
122 changes: 29 additions & 93 deletions packages/kami-design/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ import commonjs from '@rollup/plugin-commonjs'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'

const packageJson = require('./package.json')

const globals = {
// @ts-ignore
...(packageJson?.dependencies || {}),
}

const dir = 'dist'

/**
* @type {import('rollup').RollupOptions[]}
*/
const config = [
{
input: './index.ts',
const buildEntryFileConfig = (filename, config) => {
const baseFilenameWithoutExt = filename.replace(/\.[jt]sx?$/, '')
const { plugins = [] } = config || {}
return {
input: `./${baseFilenameWithoutExt}.ts`,
// ignore lib
external: [
'react',
Expand All @@ -36,29 +26,31 @@ const config = [

output: [
{
file: `${dir}/index.cjs`,
file: `${dir}/${baseFilenameWithoutExt}.cjs`,
format: 'cjs',
sourcemap: true,
},
{
file: `${dir}/index.min.cjs`,
file: `${dir}/${baseFilenameWithoutExt}.min.cjs`,
format: 'cjs',
sourcemap: true,
plugins: [terser()],
},
{
file: `${dir}/index.js`,
file: `${dir}/${baseFilenameWithoutExt}.js`,
format: 'esm',
sourcemap: true,
},
{
file: `${dir}/index.min.js`,
file: `${dir}/${baseFilenameWithoutExt}.min.js`,
format: 'esm',
sourcemap: true,
plugins: [terser()],
},
],
plugins: [
...plugins,

nodeResolve(),
commonjs({ include: 'node_modules/**' }),
typescript({
Expand Down Expand Up @@ -97,87 +89,31 @@ const config = [
],

treeshake: true,
},
}
}

// TODO merge
const packageJson = require('./package.json')

{
input: './index.windi.ts',
// ignore lib
external: [
'react',
'react-dom',
'lodash',
'lodash-es',
...Object.keys(globals),
],
const globals = {
// @ts-ignore
...(packageJson?.dependencies || {}),
}

output: [
{
file: `${dir}/index.windi.cjs`,
format: 'cjs',
sourcemap: true,
},
{
file: `${dir}/index.windi.min.cjs`,
format: 'cjs',
sourcemap: true,
plugins: [terser()],
},
{
file: `${dir}/index.windi.js`,
format: 'esm',
sourcemap: true,
},
{
file: `${dir}/index.windi.min.js`,
format: 'esm',
sourcemap: true,
plugins: [terser()],
},
],
const dir = 'dist'

/**
* @type {import('rollup').RollupOptions[]}
*/
const config = [
buildEntryFileConfig('index.ts'),

// TODO merge
buildEntryFileConfig('index.windi.ts', {
plugins: [
// @ts-ignore
...WindiCSS(),
nodeResolve(),
commonjs({ include: 'node_modules/**' }),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
}),
css({
// extract: true,
}),

// @ts-ignore
peerDepsExternal(),

esbuild({
// All options are optional
include: /\.[jt]sx?$/, // default, inferred from `loaders` option
exclude: /node_modules/, // default
sourceMap: true, // default
minify: process.env.NODE_ENV === 'production',
target: 'es2017', // default, or 'es20XX', 'esnext'
jsx: 'transform', // default, or 'preserve'
jsxFactory: 'React.createElement',
jsxFragment: 'React.Fragment',
// Like @rollup/plugin-replace

tsconfig: 'tsconfig.json', // default
// Add extra loaders
loaders: {
// Add .json files support
// require @rollup/plugin-commonjs
'.json': 'json',
// Enable JSX in .js files too
'.js': 'jsx',
},
}),
],

treeshake: true,
},
}),
]

export default config
4 changes: 2 additions & 2 deletions packages/kami-design/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true,
"baseUrl": ".",
"paths": {
"~": [
Expand All @@ -41,6 +40,7 @@
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
"**/*.tsx",
"./*.d.ts"
]
}
5 changes: 5 additions & 0 deletions packages/kami-design/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
]
}
},
"include": [
"**/*.ts",
"**/*.tsx",
"./*.d.ts"
],
"exclude": [
"__tests__/**/*",
"**/*.test.ts"
Expand Down
Loading

0 comments on commit 504f8af

Please sign in to comment.