From 807f0d161a3e9e53a7c3b39321d3b479d70fb175 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 28 Nov 2024 19:01:26 +0800 Subject: [PATCH] feat: add bundle test env --- packages/bundle/index.html | 40 +++++++++++++++++++++ packages/bundle/package.json | 25 +++++++++++++ packages/bundle/rollup.config.mjs | 16 +++++++++ packages/bundle/src/index.ts | 59 +++++++++++++++++++++++++++++++ packages/bundle/tsconfig.json | 11 ++++++ packages/bundle/vite.config.js | 13 +++++++ packages/bundle/webpack.config.js | 9 +++++ 7 files changed, 173 insertions(+) create mode 100644 packages/bundle/index.html create mode 100644 packages/bundle/package.json create mode 100644 packages/bundle/rollup.config.mjs create mode 100644 packages/bundle/src/index.ts create mode 100644 packages/bundle/tsconfig.json create mode 100644 packages/bundle/vite.config.js create mode 100644 packages/bundle/webpack.config.js diff --git a/packages/bundle/index.html b/packages/bundle/index.html new file mode 100644 index 00000000000..1b749edc888 --- /dev/null +++ b/packages/bundle/index.html @@ -0,0 +1,40 @@ + + + + + + G6 Bundler Test + + + +
+ + + + diff --git a/packages/bundle/package.json b/packages/bundle/package.json new file mode 100644 index 00000000000..56fc0694e4a --- /dev/null +++ b/packages/bundle/package.json @@ -0,0 +1,25 @@ +{ + "private": true, + "scripts": { + "build": "run-s build:*", + "build:rollup": "rollup -c", + "build:vite": "vite build", + "build:webpack": "webpack", + "ci": "npm run build" + }, + "dependencies": { + "@antv/g6": "workspace:*" + }, + "devDependencies": { + "@rollup/plugin-commonjs": "^25.0.8", + "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", + "rollup": "^4.27.4", + "rollup-plugin-polyfill-node": "^0.13.0", + "swc": "^1.0.11", + "vite": "^5.4.11", + "webpack": "^5.96.1", + "webpack-cli": "^5.1.4" + } +} diff --git a/packages/bundle/rollup.config.mjs b/packages/bundle/rollup.config.mjs new file mode 100644 index 00000000000..5288b2872c8 --- /dev/null +++ b/packages/bundle/rollup.config.mjs @@ -0,0 +1,16 @@ +import commonjs from '@rollup/plugin-commonjs'; +import resolve from '@rollup/plugin-node-resolve'; +import terser from '@rollup/plugin-terser'; +import typescript from '@rollup/plugin-typescript'; +import nodePolyfills from 'rollup-plugin-polyfill-node'; + +export default { + input: 'src/index.ts', + output: { + file: 'dist/rollup/g6.umd.js', + name: 'g6', + format: 'umd', + sourcemap: false, + }, + plugins: [nodePolyfills(), resolve(), commonjs(), typescript(), terser()], +}; diff --git a/packages/bundle/src/index.ts b/packages/bundle/src/index.ts new file mode 100644 index 00000000000..cf6cce4189c --- /dev/null +++ b/packages/bundle/src/index.ts @@ -0,0 +1,59 @@ +import { Graph } from '@antv/g6'; + +const data = { + nodes: [ + { id: '0' }, + { id: '1' }, + { id: '2' }, + { id: '3' }, + { id: '4' }, + { id: '5' }, + { id: '6' }, + { id: '7' }, + { id: '8' }, + { id: '9' }, + ], + edges: [ + { source: '0', target: '1' }, + { source: '0', target: '2' }, + { source: '1', target: '4' }, + { source: '0', target: '3' }, + { source: '3', target: '4' }, + { source: '4', target: '5' }, + { source: '4', target: '6' }, + { source: '5', target: '7' }, + { source: '5', target: '8' }, + { source: '8', target: '9' }, + { source: '2', target: '9' }, + { source: '3', target: '9' }, + ], +}; + +const graph = new Graph({ + container: 'container', + autoFit: 'view', + animation: false, + data, + layout: { + type: 'antv-dagre', + nodeSize: [60, 30], + nodesep: 60, + ranksep: 40, + controlPoints: true, + }, + node: { + type: 'rect', + style: { + size: [60, 30], + radius: 8, + labelText: (d) => d.id, + labelBackground: true, + }, + }, + edge: { + type: 'polyline', + }, + behaviors: ['drag-element', 'drag-canvas', 'zoom-canvas'], +}); + +graph.render(); diff --git a/packages/bundle/tsconfig.json b/packages/bundle/tsconfig.json new file mode 100644 index 00000000000..d04f33dae42 --- /dev/null +++ b/packages/bundle/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "lib", + "paths": { + "@antv/g6": ["../g6/src/index.ts"] + } + }, + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/bundle/vite.config.js b/packages/bundle/vite.config.js new file mode 100644 index 00000000000..5cdc1288202 --- /dev/null +++ b/packages/bundle/vite.config.js @@ -0,0 +1,13 @@ +import { defineConfig } from 'vite'; + +export default defineConfig({ + build: { + lib: { + entry: 'src/index.ts', + name: 'g6', + fileName: 'g6', + formats: ['umd'], + }, + outDir: 'dist/vite', + }, +}); diff --git a/packages/bundle/webpack.config.js b/packages/bundle/webpack.config.js new file mode 100644 index 00000000000..e94340679bc --- /dev/null +++ b/packages/bundle/webpack.config.js @@ -0,0 +1,9 @@ +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + filename: 'g6.umd.js', + path: path.resolve(__dirname, 'dist/webpack'), + }, +};