Skip to content

Commit

Permalink
Try implementing path aliases again
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkulpinski committed Jan 12, 2024
1 parent e05d9f1 commit 41077e4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
browser: true,
commonjs: true,
es6: true,
node: true,
},

// Base config
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"tailwind-merge": "^2.2.0",
"tailwindcss": "^3.4.1",
"tailwindcss-animate": "^1.0.7",
"tsc-alias": "^1.8.8",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^4.5.1"
Expand Down
17 changes: 13 additions & 4 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { babel } from "@rollup/plugin-babel"
import commonjs from "@rollup/plugin-commonjs"
import resolve from "@rollup/plugin-node-resolve"
import { nodeResolve } from "@rollup/plugin-node-resolve"
import terser from "@rollup/plugin-terser"
import typescript from "@rollup/plugin-typescript"
import { createRequire } from "node:module"
import { dts } from "rollup-plugin-dts"
import peerDepsExternal from "rollup-plugin-peer-deps-external"
import { exec } from "node:child_process"
import { promisify } from "node:util"

const requireFile = createRequire(import.meta.url)
const packageJson = requireFile("./package.json")

// Resolve typescript aliases
const tscAlias = () => ({
buildStart: async () => {
await promisify(exec)("tsc-alias")
},
})

export default [
{
input: "src/index.ts",
Expand All @@ -28,10 +37,10 @@ export default [
],
plugins: [
peerDepsExternal(),
resolve(),
typescript(),
nodeResolve(),
commonjs(),
terser(),
typescript(),
babel({
babelHelpers: "bundled",
extensions: [".ts", ".tsx"],
Expand All @@ -43,6 +52,6 @@ export default [
{
input: "dist/index.d.ts",
output: [{ file: "dist/index.d.ts", format: "es" }],
plugins: [dts()],
plugins: [tscAlias(), dts()],
},
]
10 changes: 5 additions & 5 deletions src/ui/AvatarGroup/AvatarGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ComponentPropsWithoutRef, HTMLAttributes, ReactNode } from "react"
import { forwardRef } from "react"

import type { AvatarElement, AvatarProps } from "../Avatar"
import { Avatar } from "../Avatar"
import type { avatarVariants } from "../Avatar/Avatar.variants"
import { type VariantProps, cx } from "../../shared/cva"
import { isReactElement } from "../../shared/helpers"
import { type VariantProps, cx } from "~/shared/cva"
import { isReactElement } from "~/shared/helpers"
import type { AvatarElement, AvatarProps } from "~/ui/Avatar"
import { Avatar } from "~/ui/Avatar"
import type { avatarVariants } from "~/ui/Avatar/Avatar.variants"

import { avatarGroupItemVariants, avatarGroupVariants } from "./AvatarGroup.variants"

Expand Down
2 changes: 1 addition & 1 deletion src/ui/AvatarGroup/AvatarGroup.variants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cva } from "../../shared/cva"
import { cva } from "~/shared/cva"

export const avatarGroupVariants = cva({
base: "flex flex-wrap items-center gap-y-1",
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"paths": {
"~/*": [
"./src/*"
]
}
},
"include": [
"src"
Expand Down
2 changes: 2 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
import path from "path"

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: { "~": path.resolve(__dirname, "./src") },
extensions: [".mdx", ".mjs", ".ts", ".tsx", ".js", ".jsx"],
},
})

0 comments on commit 41077e4

Please sign in to comment.