Skip to content

Commit

Permalink
feat: add bundle test env (#6578)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca authored Dec 3, 2024
1 parent 2f58671 commit ca48a19
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/bundle/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>G6 Bundler Test</title>
</head>
<body>
<select id="switch-bundler">
<option value="">None</option>
<option value="webpack">Webpack</option>
<option value="vite">Vite</option>
<option value="rollup">Rollup</option>
</select>
<div id="container"></div>

<script>
const select = document.getElementById('switch-bundler');

function setBundler(value) {
if (!value) return;
const container = document.getElementById('container');
container.innerHTML = '';

const currentScript = document.getElementById('g6-script');
if (currentScript) document.body.removeChild(currentScript);

const script = document.createElement('script');
script.id = 'g6-script';
script.src = `./dist/${value}/g6.umd.js`;
document.body.appendChild(script);
}

select.addEventListener('change', (e) => {
setBundler(e.target.value);
console.log('switch bundler:', e.target.value);
});
</script>
</body>
</html>
25 changes: 25 additions & 0 deletions packages/bundle/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
16 changes: 16 additions & 0 deletions packages/bundle/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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()],
};
59 changes: 59 additions & 0 deletions packages/bundle/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();
11 changes: 11 additions & 0 deletions packages/bundle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"strict": true,
"outDir": "lib",
"paths": {
"@antv/g6": ["../g6/src/index.ts"]
}
},
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
13 changes: 13 additions & 0 deletions packages/bundle/vite.config.js
Original file line number Diff line number Diff line change
@@ -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',
},
});
9 changes: 9 additions & 0 deletions packages/bundle/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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'),
},
};

0 comments on commit ca48a19

Please sign in to comment.