Skip to content

Commit

Permalink
refactor: build and fix ts (#574)
Browse files Browse the repository at this point in the history
* feat: build system

* refactor: remove preloading optimization for dependencies in Vite config
  • Loading branch information
productdevbook authored Nov 21, 2024
1 parent 59cba4f commit 531f4b8
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 80 deletions.
7 changes: 4 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oku-ui/primitives",
"type": "module",
"version": "0.7.3",
"version": "0.7.4-alpha.5",
"license": "MIT",
"funding": "https://github.com/sponsors/productdevbook",
"homepage": "https://oku-ui.com/primitives",
Expand Down Expand Up @@ -96,7 +96,7 @@
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"@vue/shared": "^3.4.31"
"vue": ">= 3.5.0"
},
"dependencies": {
"@floating-ui/dom": "^1.6.12",
Expand All @@ -107,7 +107,7 @@
"devDependencies": {
"@tsconfig/node20": "^20.1.4",
"@types/jsdom": "^21.1.7",
"@types/node": "^22.0.0",
"@types/node": "^22.9.0",
"@vitejs/plugin-vue": "^5.1.4",
"@vitejs/plugin-vue-jsx": "^4.0.1",
"@vue/test-utils": "^2.4.6",
Expand All @@ -123,6 +123,7 @@
"vite-plugin-dts": "^4.3.0",
"vite-plugin-externalize-deps": "^0.8.0",
"vite-plugin-pages": "^0.32.3",
"vite-tsconfig-paths": "^5.1.3",
"vitest": "^2.1.4",
"vue": "^3.5.12",
"vue-router": "^4.4.5",
Expand Down
6 changes: 2 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ export * from './toggle/index.ts'
export * from './toggle-group/index.ts'
export * from './toolbar/index.ts'
export * from './tooltip/index.ts'


export { Primitive, type PrimitiveProps } from './primitive/index.ts'
export { VisuallyHidden, type VisuallyHiddenProps } from './visually-hidden/index.ts'
export * from './primitive/index.ts'
export * from './visually-hidden/index.ts'
5 changes: 3 additions & 2 deletions packages/core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"module": "esnext",
"moduleResolution": "node",
"paths": {
"@/*": ["src/*"],
"@vue/shared": ["node_modules/@vue/shared"]
"@/*": ["src/*"]
},
"resolveJsonModule": true,
"types": [
"node"
],
"allowImportingTsExtensions": true,
"strict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"declaration": false,
"outDir": "dist",
"sourceMap": true,
Expand Down
97 changes: 39 additions & 58 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,65 @@
import process from 'node:process'
// import { externalizeDeps } from 'vite-plugin-externalize-deps'

import { execSync } from 'node:child_process'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { globbySync } from 'globby'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import pkg from './package.json'

const projectRootDir = resolve(__dirname)

// https://vitejs.dev/config/
export default defineConfig({
define: {
__DEV__: process.env.NODE_ENV !== 'production',
},
plugins: [
// externalizeDeps(),
vue(),
vue({
template: {
compilerOptions: {
hoistStatic: true,
cacheHandlers: true,
},
},
}),
vueJsx(),
dts({
outDir: 'dist',
exclude: ['src/**/__tests__/*', 'src/**/stories/*'],
compilerOptions: {
composite: false,
declaration: true,
declarationMap: true,
},
tsconfigPath: 'tsconfig.build.json',
afterBuild: async () => {
console.log('dts afterBuild')
// pnpm build:plugins
execSync('pnpm build:plugins', { stdio: 'inherit', cwd: resolve(__dirname, '../plugins') })
execSync('pnpm generate:plugins', { stdio: 'inherit', cwd: resolve(__dirname, '../plugins') })
execSync('pnpm lint:fix', { stdio: 'inherit', cwd: resolve(__dirname, '../..') })
},
exclude: ['src/test/**', 'src/**/stories/**', 'src/**/*.stories.vue'],
rollupTypes: true,
}),
],
resolve: {
alias: {
'@': resolve(projectRootDir, 'src'),
},
dedupe: ['vue', '@vue/runtime-core'],
},
build: {
copyPublicDir: false,
minify: false,
target: 'esnext',
sourcemap: true,
lib: {
name: 'oku-ui-primitives',
formats: ['es'],
entry: [
...globbySync('src/**/*.ts', { ignore: [
'**/__tests__/**',
'**/stories/**',
'**/*.stories.ts',
] }),
'src/index.ts',
],
fileName: (_, name) => `${name}.mjs`,
entry: {
index: resolve(__dirname, 'src/index.ts'),
},
},
target: 'esnext',
rollupOptions: {
output: {
esModule: true,
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
external: [
'vue',
'@vue/shared',
'@floating-ui/dom',
'@floating-ui/utils',
'@floating-ui/vue',
'aria-hidden',
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
],
output: {
manualChunks: (id) => {
// Daha basit chunk stratejisi
const chunks = id.match(/[/\\]src[/\\](.*?)[/\\]/)
return chunks ? chunks[1] : null
},
exports: 'named',
chunkFileNames: '[name].mjs',
assetFileNames: 'index.css',
hoistTransitiveImports: false,
minifyInternalExports: true,
},
},

},
resolve: {
alias: {
'@oku-ui': fileURLToPath(new URL('./src', import.meta.url)),
},
},
// resolve: {
// alias: {
// '~': fileURLToPath(new URL('./src', import.meta.url)),
// },
// },
})
57 changes: 44 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 531f4b8

Please sign in to comment.