Quellcode durchsuchen

build @growi/ui with vite

Yuki Takei vor 3 Jahren
Ursprung
Commit
4374bdad8b

+ 1 - 0
packages/ui/.gitignore

@@ -1 +1,2 @@
 /dist
+/types

+ 11 - 9
packages/ui/package.json

@@ -4,22 +4,24 @@
   "description": "GROWI UI Libraries",
   "license": "MIT",
   "keywords": ["growi"],
-  "main": "dist/cjs/index.js",
-  "module": "dist/esm/index.js",
-  "files": ["dist"],
+  "type": "module",
+  "types": "types/index.d.ts",
+  "files": [
+    "dist",
+    "types"
+  ],
   "scripts": {
-    "build": "run-p build:*",
-    "build:cjs": "tsc -p tsconfig.build.cjs.json && tsc-alias -p tsconfig.build.cjs.json",
-    "build:esm": "tsc -p tsconfig.build.esm.json && tsc-alias -p tsconfig.build.esm.json",
-    "clean": "npx -y shx rm -rf dist",
-    "lint:js": "eslint **/*.{js,jsx,ts,tsx}",
+    "build": "vite build",
+    "clean": "npx -y shx rm -rf dist types",
+    "dev": "vite build --mode dev",
+    "watch": "yarn dev -w",
+    "lint:js": "eslint **/*.{js,ts}",
     "lint": "npm-run-all -p lint:*"
   },
   "dependencies": {
     "@growi/core": "^6.0.8-RC.0"
   },
   "devDependencies": {
-    "eslint-plugin-regex": "^1.8.0",
     "react": "^18.2.0"
   }
 }

+ 1 - 1
packages/ui/src/components/Attachment/Attachment.tsx → packages/ui/src/components/Attachment.tsx

@@ -2,7 +2,7 @@ import React from 'react';
 
 import { HasObjectId, IAttachment } from '@growi/core';
 
-import { UserPicture } from '../User/UserPicture';
+import { UserPicture } from './User/UserPicture';
 
 type AttachmentProps = {
   attachment: IAttachment & HasObjectId,

+ 0 - 0
packages/ui/src/components/SearchPage/FootstampIcon.tsx → packages/ui/src/components/FootstampIcon.tsx


+ 1 - 1
packages/ui/src/components/PagePath/PageListMeta.tsx

@@ -4,7 +4,7 @@ import assert from 'assert';
 
 import { templateChecker, pagePathUtils, IPageHasId } from '@growi/core';
 
-import { FootstampIcon } from '../SearchPage/FootstampIcon';
+import { FootstampIcon } from '../FootstampIcon';
 
 const { isTopPage } = pagePathUtils;
 const { checkTemplatePath } = templateChecker;

+ 0 - 10
packages/ui/src/index.ts

@@ -1,10 +0,0 @@
-export * from './interfaces/breakpoints';
-
-export * from './components/Attachment/Attachment';
-export * from './components/PagePath/PageListMeta';
-export * from './components/PagePath/PagePathLabel';
-export * from './components/SearchPage/FootstampIcon';
-export * from './components/User/UserPicture';
-
-export * from './utils/browser-utils';
-export * from './utils/use-fullscreen';

+ 2 - 0
packages/ui/src/utils/index.ts

@@ -0,0 +1,2 @@
+export * from './browser-utils';
+export * from './use-fullscreen';

+ 0 - 18
packages/ui/tsconfig.base.json

@@ -1,18 +0,0 @@
-{
-  "$schema": "http://json.schemastore.org/tsconfig",
-  "extends": "../../tsconfig.base.json",
-  "compilerOptions": {
-    "module": "esnext",
-    "jsx": "react",
-    "noFallthroughCasesInSwitch": true,
-    "noUnusedLocals": true,
-    "noUnusedParameters": true,
-    "strict": true,
-  },
-  "include": [
-    "src"
-  ],
-  "exclude": [
-    "src/test"
-  ]
-}

+ 0 - 19
packages/ui/tsconfig.build.cjs.json

@@ -1,19 +0,0 @@
-{
-  "$schema": "http://json.schemastore.org/tsconfig",
-  "extends": "./tsconfig.base.json",
-  "compilerOptions": {
-    "module": "commonjs",
-
-    "rootDir": "./src",
-    "outDir": "dist/cjs",
-    "declaration": true,
-    "noResolve": false,
-    "preserveConstEnums": true,
-    "sourceMap": false,
-    "noEmit": false,
-
-    "baseUrl": ".",
-    "paths": {
-    }
-  }
-}

+ 0 - 17
packages/ui/tsconfig.build.esm.json

@@ -1,17 +0,0 @@
-{
-  "$schema": "http://json.schemastore.org/tsconfig",
-  "extends": "./tsconfig.base.json",
-  "compilerOptions": {
-    "rootDir": "./src",
-    "outDir": "dist/esm",
-    "declaration": true,
-    "noResolve": false,
-    "preserveConstEnums": true,
-    "sourceMap": false,
-    "noEmit": false,
-
-    "baseUrl": ".",
-    "paths": {
-    }
-  }
-}

+ 0 - 17
packages/ui/tsconfig.build.json

@@ -1,17 +0,0 @@
-{
-  "$schema": "http://json.schemastore.org/tsconfig",
-  "extends": "./tsconfig.base.json",
-  "compilerOptions": {
-    "rootDir": "./src",
-    "outDir": "dist/esm",
-    "declaration": true,
-    "noResolve": false,
-    "preserveConstEnums": true,
-    "sourceMap": false,
-    "noEmit": false,
-
-    "baseUrl": ".",
-    "paths": {
-    }
-  }
-}

+ 7 - 3
packages/ui/tsconfig.json

@@ -1,11 +1,15 @@
 {
   "$schema": "http://json.schemastore.org/tsconfig",
-  "extends": "./tsconfig.base.json",
+  "extends": "../../tsconfig.base.json",
   "compilerOptions": {
+    "jsx": "react-jsxdev",
+
     "baseUrl": ".",
     "paths": {
       "~/*": ["./src/*"],
-      "@growi/*": ["../*/src"]
     }
-  }
+  },
+  "include": [
+    "src"
+  ]
 }

+ 35 - 0
packages/ui/vite.config.ts

@@ -0,0 +1,35 @@
+import path from 'path';
+
+import react from '@vitejs/plugin-react';
+import glob from 'glob';
+import { defineConfig } from 'vite';
+import dts from 'vite-plugin-dts';
+
+// https://vitejs.dev/config/
+export default defineConfig({
+  plugins: [
+    react(),
+    dts({ outputDir: 'types' }),
+  ],
+  build: {
+    outDir: 'dist',
+    lib: {
+      entry: glob.sync(path.resolve(__dirname, 'src/**/*.{ts,tsx}')),
+      name: 'ui-libs',
+      formats: ['es'],
+    },
+    rollupOptions: {
+      output: {
+        preserveModules: true,
+        preserveModulesRoot: 'src',
+      },
+      external: [
+        'react', 'react-dom',
+        'assert',
+        'reactstrap',
+        /^next\/.*/,
+        /^@growi\/.*/,
+      ],
+    },
+  },
+});