Skip to content

Commit

Permalink
fix: vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Dec 23, 2023
1 parent 9deb350 commit 60c7565
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 60 deletions.
4 changes: 3 additions & 1 deletion packages-legacy/plugin-generate-template/src/index.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ extension({
});

function runEditor() {
const editor = document.createElement('erd-editor');
const editor = document.createElement('vuerd-editor');
editor.automaticLayout = true;
document.body.style.margin = '0';
document.body.style.height = '100vh';
document.body.appendChild(editor);
}

Expand Down
11 changes: 3 additions & 8 deletions packages-legacy/vuerd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

> Entity-Relationship Diagram Editor
[![npm version](https://img.shields.io/npm/v/vuerd.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/vuerd) [![VS Marketplace version](https://vsmarketplacebadge.apphb.com/version-short/dineug.vuerd-vscode.svg?style=flat-square&color=blue&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=dineug.vuerd-vscode) [![APM](https://img.shields.io/apm/v/vuerd-atom?color=blue&style=flat-square&logo=atom)](https://atom.io/packages/vuerd-atom) [![GitHub](https://img.shields.io/github/license/vuerd/vuerd?style=flat-square&color=blue)](https://github.com/vuerd/vuerd/blob/master/LICENSE) [![PRs](https://img.shields.io/badge/PRs-welcome-blue?style=flat-square)](https://github.com/vuerd/vuerd/pulls) [![CI](https://img.shields.io/github/workflow/status/vuerd/vuerd/CI?label=CI&logo=github&style=flat-square)](https://github.com/vuerd/vuerd/actions)

## ERD

![vuerd](https://github.com/vuerd/vuerd/blob/master/img/vuerd-erd.gif?raw=true)
![vuerd](https://github.com/dineug/erd-editor/blob/main/img/vuerd-erd.gif?raw=true)

## Document

- [Playground](https://vuerd.github.io)
- [Import SQL DDL support syntax](https://github.com/vuerd/vuerd/blob/master/packages/sql-ddl-parser/src/SQL_DDL_Test_Case.md)
- [Import SQL DDL support syntax](https://github.com/dineug/erd-editor/blob/main/packages-legacy/sql-ddl-parser/src/SQL_DDL_Test_Case.md)
- [vscode extension](https://marketplace.visualstudio.com/items?itemName=dineug.vuerd-vscode)
- [atom extension](https://atom.io/packages/vuerd-atom)

## interface ERDEditorElement

Expand Down Expand Up @@ -275,7 +272,7 @@ container.appendChild(editor);
## CDN Quick Start

```html
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<title>vuerd demo</title>
Expand All @@ -299,8 +296,6 @@ container.appendChild(editor);
<body>
<erd-editor></erd-editor>
<script src="https://cdn.jsdelivr.net/npm/vuerd/dist/vuerd.min.js"></script>
<!-- or module -->
<!-- <script type="module" src="https://cdn.jsdelivr.net/npm/vuerd/dist/vuerd.esm.js"></script> -->
<script>
const editor = document.querySelector('erd-editor');
window.addEventListener('resize', () => {
Expand Down
19 changes: 10 additions & 9 deletions packages-legacy/vuerd/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"name": "vuerd",
"version": "2.2.11",
"version": "2.2.12",
"private": true,
"description": "ERD editor",
"type": "module",
"main": "./dist/vuerd.js",
"main": "./dist/vuerd.min.js",
"module": "./dist/vuerd.js",
"typings": "./types/index.d.ts",
"exports": {
".": {
"import": {
"types": "./types/index.d.ts",
"default": "./dist/vuerd.js"
}
},
"require": "./dist/vuerd.min.js"
}
},
"files": [
Expand All @@ -27,15 +29,14 @@
"database",
"diagram"
],
"homepage": "https://github.com/vuerd/vuerd#readme",
"bugs": {
"url": "https://github.com/vuerd/vuerd/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/vuerd/vuerd.git",
"directory": "packages/vuerd"
"url": "https://github.com/dineug/erd-editor.git"
},
"bugs": {
"url": "https://github.com/dineug/erd-editor/issues"
},
"homepage": "https://github.com/dineug/erd-editor#readme",
"author": "dineug <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages-legacy/vuerd/src/index.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import './index';
function runEditor() {
const editor = document.createElement('vuerd-editor');
editor.automaticLayout = true;
document.body.style.margin = '0';
document.body.style.height = '100vh';
document.body.appendChild(editor);
}

Expand Down
35 changes: 25 additions & 10 deletions packages-legacy/vuerd/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,50 @@ import tsconfigPaths from 'vite-tsconfig-paths';

const pkg = JSON.parse(readFileSync('package.json', { encoding: 'utf8' }));

const banner = `/*!
* ${pkg.name}
* @version ${pkg.version} | ${new Date().toDateString()}
* @author ${pkg.author}
* @license ${pkg.license}
*/`;

export default defineConfig(({ command }) => {
const isBuild = command === 'build';

return {
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
...(isBuild ? {'process.env.NODE_ENV': JSON.stringify('production')} : {}),
...(isBuild
? { 'process.env.NODE_ENV': JSON.stringify('production') }
: {}),
},
build: {
lib: {
entry: './src/index.ts',
name: pkg.name,
fileName: 'vuerd',
formats: ['es'],
fileName: format => (format === 'es' ? 'vuerd.js' : 'vuerd.min.js'),
formats: ['es', 'umd'],
},
rollupOptions: {
output: {
banner,
},
},
},
resolve: {
dedupe: ['lit-html']
dedupe: ['lit-html'],
},
plugins: [
tsconfigPaths(),
isBuild && strip({
debugger: true,
include: '**/*.ts',
functions: ['Logger.debug', 'Logger.log', 'console.log'],
})
isBuild &&
strip({
debugger: true,
include: '**/*.ts',
functions: ['Logger.debug', 'Logger.log', 'console.log'],
}),
].filter(Boolean),
server: {
open: true,
},
}
};
});
1 change: 1 addition & 0 deletions packages/erd-editor-schema/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';

import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
// @ts-ignore
import tspCompiler from 'ts-patch/compiler';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand Down
1 change: 1 addition & 0 deletions packages/erd-editor-shiki-worker/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';

import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
// @ts-ignore
import tspCompiler from 'ts-patch/compiler';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand Down
20 changes: 2 additions & 18 deletions packages/erd-editor-vscode-bridge/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { isObject } from '@dineug/shared';
import { isObject, safeCallback } from '@dineug/shared';

import {
AnyAction,
Callback,
ReducerRecord,
ValuesType,
} from '@/internal-types';
import { AnyAction, ReducerRecord, ValuesType } from '@/internal-types';
import {
AccentColor,
Appearance,
Expand Down Expand Up @@ -81,17 +76,6 @@ type BridgeActionMap = {
[BridgeActionType.webviewUpdateReadonly]: boolean;
};

function safeCallback<F extends Callback>(
callback?: F | void,
...args: Parameters<F>
) {
try {
return callback?.(...args);
} catch (e) {
console.error(e);
}
}

function createAction<P = void>(type: string) {
function actionCreator(payload: P): AnyAction<P> {
return { type, payload };
Expand Down
2 changes: 0 additions & 2 deletions packages/erd-editor-vscode-bridge/src/internal-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ type Reducer<K extends keyof M, M> = (action: Action<K, M>) => void;
export type ReducerRecord<K extends keyof M, M> = {
[P in K]: Reducer<P, M>;
};

export type Callback = (...args: any[]) => any;
1 change: 1 addition & 0 deletions packages/erd-editor-vscode-bridge/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';

import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
// @ts-ignore
import tspCompiler from 'ts-patch/compiler';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand Down
7 changes: 2 additions & 5 deletions packages/erd-editor-vscode-webview/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig(({ command, mode }) => {
const envDir = './environment';
process.env = {
...process.env,
...loadEnv(mode, envDir),
};
const isModern = process.env.VITE_TARGET === 'modern';
const env = loadEnv(mode, envDir);
const isModern = env.VITE_TARGET === 'modern';
const entry = isModern ? './src/index.ts' : './src/index-legacy.ts';
const outDir = '../erd-editor-vscode/'.concat(
isModern ? 'public' : 'public-legacy'
Expand Down
8 changes: 3 additions & 5 deletions packages/erd-editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFileSync } from 'node:fs';
import rHtml from '@dineug/vite-plugin-r-html';
import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
// @ts-ignore
import tspCompiler from 'ts-patch/compiler';
import { defineConfig, loadEnv } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand All @@ -18,13 +19,10 @@ const banner = `/*!

export default defineConfig(({ command, mode }) => {
const envDir = './environment';
process.env = {
...process.env,
...loadEnv(mode, envDir),
};
const env = loadEnv(mode, envDir);
const isServe = command === 'serve';
const isBuild = command === 'build';
const isLib = process.env.VITE_TARGET === 'lib';
const isLib = env.VITE_TARGET === 'lib';

return {
envDir,
Expand Down
5 changes: 3 additions & 2 deletions packages/schema-sql-parser/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFileSync } from 'node:fs';

import typescript from '@rollup/plugin-typescript';
import { visualizer } from 'rollup-plugin-visualizer';
// @ts-ignore
import tspCompiler from 'ts-patch/compiler';
import { loadEnv } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
Expand All @@ -11,9 +12,9 @@ const pkg = JSON.parse(readFileSync('package.json', { encoding: 'utf8' }));

export default defineConfig(({ command, mode }) => {
const envDir = './environment';
process.env = { ...process.env, ...loadEnv(mode, envDir) };
const env = loadEnv(mode, envDir);
const isBuild = command === 'build';
const isLib = process.env.VITE_TARGET === 'lib';
const isLib = env.VITE_TARGET === 'lib';

return {
envDir,
Expand Down

0 comments on commit 60c7565

Please sign in to comment.