build: ts build

This commit is contained in:
07akioni 2021-02-03 00:48:31 +08:00
parent ea3744dc1b
commit 43658733e4
16 changed files with 37 additions and 91 deletions

1
.gitignore vendored
View File

@ -17,4 +17,3 @@ es
coverage
/fonts
/site
/src-mirror

View File

@ -1,67 +0,0 @@
const fs = require('fs-extra')
const path = require('path')
const rollup = require('rollup')
const vuePlugin = require('rollup-plugin-vue')
const srcDir = path.resolve(__dirname, '../src')
const srcMirrorDir = path.resolve(__dirname, '../src-mirror')
const projectDir = path.resolve(__dirname, '..')
async function findAndReplace (filePath, pattern, target) {
const content = (await fs.readFile(filePath)).toString()
if (pattern.test(content)) {
await fs.writeFile(filePath, content.replace(pattern, target))
}
}
async function traverse (root) {
const dir = await fs.opendir(root)
for await (const dirent of dir) {
const { name } = dirent
if (dirent.isDirectory()) {
await traverse(path.resolve(root, dirent.name))
} else {
const filePath = path.resolve(root, name)
// change all vue import to js
await findAndReplace(filePath, /\.vue/g, '.js')
// build js output for vue file
if (filePath.endsWith('.vue')) {
console.log('make', filePath.replace(projectDir, ''))
const rollupInputOptions = {
input: filePath,
external: (id) => {
return !/\.vue\?vue/.test(id)
},
plugins: [
vuePlugin({
file: false
})
]
}
const rollupOutputOptions = {
format: 'esm',
file: filePath.replace(/\.vue$/, '.js')
}
const bundle = await rollup.rollup(rollupInputOptions)
await bundle.write(rollupOutputOptions)
// remove original file
await fs.unlink(filePath)
}
}
}
}
;(async () => {
try {
if (await fs.pathExists(srcMirrorDir)) {
await fs.emptyDir(srcMirrorDir)
await fs.remove(srcMirrorDir)
}
await fs.mkdir(srcMirrorDir)
await fs.copy(srcDir, srcMirrorDir)
await fs.emptyDir(path.resolve(srcMirrorDir, '_deprecated/icons'))
traverse(srcMirrorDir)
} catch (err) {
console.log(err)
}
})()

View File

@ -7,7 +7,7 @@
const fs = require('fs-extra')
const path = require('path')
const iconPath = path.resolve(__dirname, '..', 'src', '_deprecated', 'icons')
const iconPath = path.resolve(__dirname, '..', 'compat', 'icons')
const cjsIconPath = path.resolve(__dirname, '..', 'lib', 'icons')
const esmIconPath = path.resolve(__dirname, '..', 'es', 'icons')

View File

@ -7,14 +7,15 @@
"scripts": {
"start": "npm run dev",
"deprecated:build:icons": "npm run clean && node build/build-icons.js",
"build:js": "npm run gen-version && npm run clean && node build/before-build.js && rollup -c",
"build:package": "npm run gen-version && npm run clean && node build/build-icons.js && node build/before-build.js && rollup -c",
"build:js": "npm run gen-version && npm run clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
"build:package": "npm run gen-version && npm run clean && node build/build-icons.js && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json",
"build:site": "npm run build:package && ./build/before-build-site.sh && node build/restore-side-effects.js && cross-env NODE_ENV=production NODE_OPTIONS=--max-old-space-size=4096 vite build && rm -rf node_modules/naive-ui && cp site/index.html site/404.html && node build/clear-side-effects.js",
"build:doc": "npm run gen-version && npm run build && rm -rf build-doc/dist && cross-env NODE_ENV=production webpack --config build/webpack.doc.js",
"clean": "rm -rf site lib es src-mirror node_modules/naive-ui",
"clean": "rm -rf site lib es node_modules/naive-ui",
"dev": "npm run clean && npm run gen-version && cross-env NODE_ENV=development vite",
"dev:ts": "npm run clean && npm run gen-version && cross-env NODE_ENV=development TUSIMPLE=true vite",
"lint": "npm run lint:code",
"lint": "npm run lint:code && npm run lint:type",
"lint:type": "tsc --noEmit",
"lint:code": "eslint --fix \"{src,build,scripts,demo}/**/*.{js,vue,md}\"",
"format": "npm run format:code && npm run format:md",
"format:code": "prettier --write \"(src|demo)/**/*.(vue|js)\"",
@ -34,6 +35,7 @@
"registry": "***REMOVED***"
},
"files": [
"compat",
"es",
"lib",
"src",
@ -124,13 +126,13 @@
"highlight.js": "^10.4.1",
"lodash-es": "^4.17.15",
"resize-observer-polyfill": "^1.5.1",
"seemly": "^0.1.5",
"seemly": "^0.1.6",
"treemate": "^0.2.4",
"vdirs": "^0.0.3",
"vfonts": "^0.0.1",
"vooks": "0.0.8",
"vue": "^3.0.5",
"vueuc": "^0.1.1"
"vueuc": "^0.1.2"
},
"husky": {
"hooks": {

View File

@ -150,11 +150,12 @@ export default defineComponent({
ref: 'bodyLayoutInstRef',
nativeScrollbar: false,
scrollbarProps: {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
contentStyle: {
width: '100%',
boxSizing: 'border-box',
padding: this.paddingBody ? '21px 48px' : null
}
padding: this.paddingBody ? '21px 48px' : ''
} as CSSProperties
}
}
const headerProps = {

View File

@ -23,7 +23,7 @@ type UseFormItemProps<T> =
}
| {}
interface UseFormItem<T> {
export interface UseFormItem<T> {
mergedSize: ComputedRef<T>
nTriggerFormBlur: () => void
nTriggerFormChange: () => void

View File

@ -14,7 +14,7 @@ import { cardLight } from '../styles'
import type { CardTheme } from '../styles'
import style from './styles/index.cssr'
interface Segmented {
export interface Segmented {
content?: boolean | 'soft'
footer?: boolean | 'soft'
action?: boolean | 'soft'

View File

@ -39,7 +39,7 @@ function createLocalesObject (
}, defaultLocaleMap)
}
interface NaiveUI {
export interface NaiveUI {
version: string
use: (plugin: any) => void
install: Function

View File

@ -3,7 +3,7 @@ import { PropType } from 'vue'
export const positionProp = {
type: String as PropType<'static' | 'absolute'>,
default: 'static'
}
} as const
export interface LayoutRef {
scrollTo: ((options: ScrollToOptions) => void) &

View File

@ -3,7 +3,7 @@ import { VNodeChild } from 'vue'
export type Key = string | number
interface MenuOptionBase {
export interface MenuOptionBase {
key: Key
disabled?: boolean
icon?: () => VNodeChild
@ -12,7 +12,7 @@ interface MenuOptionBase {
[key: string]: unknown
}
interface MenuGroupOptionBase extends MenuOptionBase {
export interface MenuGroupOptionBase extends MenuOptionBase {
type: 'group'
children: Array<MenuOption | MenuGroupOption>
}

View File

@ -55,7 +55,7 @@ export interface RadioGroupInjection {
doUpdateValue: (value: string | number) => void
}
interface UseRadio {
export interface UseRadio {
inputRef: Ref<HTMLElement | null>
labelRef: Ref<HTMLElement | null>
mergedName: Ref<string | undefined>

View File

@ -22,7 +22,7 @@ import { scrollbarLight } from '../styles'
import type { ScrollbarTheme } from '../styles'
import style from './styles/index.cssr'
interface ScrollTo {
export interface ScrollTo {
(x: number, y: number): void
(options: {
left?: number

8
tsconfig.cjs.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "lib",
"module": "CommonJS",
"target": "ES6"
}
}

View File

@ -2,6 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "es",
"module": "ESNext"
"module": "ESNext",
"target": "ESNext"
}
}

View File

@ -11,6 +11,7 @@
"jsxFragmentFactory": "Fragment",
"module": "ES6",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"ESNext",
"DOM"

11
vue3.md
View File

@ -7,9 +7,9 @@
- fonts
- `naive-ui/lib|es/styles/fonts/*` has been removed, use [`vfonts`](https://www.npmjs.com/package/vfonts)
- icons
- `naive-ui/lib|es/icons/*` is deprecated, use [`vicons`](https://www.npmjs.com/package/vicons) instead.
- `naive-ui/lib|es/icons/*` is deprecated (vue-loader is required), use [`vicons`](https://www.npmjs.com/package/vicons) instead.
- `n-nimbus-icon` is moved to `naive-ui/compat/nimbus-icon` (vue-loader is required)
- `n-nimbus-form-card` is removed
- `n-nimbus-icon` is removed
## Components
@ -422,13 +422,14 @@
- [x] form item no label css
- [x] unify treemate ignored
- [ ] fix menu extra
- [ ] build icon
- [ ] compat
- [x] build icon
- [x] compat
- [ ] on update value api
- [ ] fix upload dragger
- [x] fix upload dragger
- [x] fix table sorter
- [x] tree 多选节点第二个 demo
- [ ] table treemate!!!
- [ ] createTheme
## Info