Skip to content

Commit

Permalink
增加 UMD 输出产物 (#8)
Browse files Browse the repository at this point in the history
* chore: add umd output

* chore: add sideeffects
  • Loading branch information
xiaoiver authored Nov 14, 2023
1 parent 7bd1576 commit 8ce5c5b
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 9 deletions.
1 change: 1 addition & 0 deletions 3d/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules

esm
lib
dist
51 changes: 50 additions & 1 deletion 3d/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# g2-extension-3d

> A placeholder for the [threed](https://github.com/antvis/G2/blob/v5/src/lib/std.ts) lib for G2.
The [threed](https://github.com/antvis/G2/blob/v5/src/lib/std.ts) lib for G2.

## Getting Started

Create a renderer and register relative plugins which provides 3D rendering capabilities:

```ts
import { Renderer as WebGLRenderer } from '@antv/g-webgl';
import { Plugin as ThreeDPlugin } from '@antv/g-plugin-3d';
import { Plugin as ControlPlugin } from '@antv/g-plugin-control';

const renderer = new WebGLRenderer();
renderer.registerPlugin(new ThreeDPlugin());
renderer.registerPlugin(new ControlPlugin());
```

Then extend the runtime of G2 with 3D lib:

```ts
import { threedlib } from '@antv/g2-extension-3d';
import { Runtime, corelib, extend } from '@antv/g2';

const Chart = extend(Runtime, { ...corelib(), ...threedlib() });
const chart = new Chart({
container: 'container',
renderer,
depth: 400,
});
```

Now we can use 3D marks like this:

```ts
chart
.point3D()
.data({});
```

## Scatter

[DEMO](https://g2.antv.antgroup.com/examples#threed-scatter)

## Line

[DEMO](https://g2.antv.antgroup.com/examples#threed-line)

## Bar

[DEMO](https://g2.antv.antgroup.com/examples#threed-bar)

22 changes: 17 additions & 5 deletions 3d/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"name": "@antv/g2-extension-3d",
"version": "0.1.0",
"version": "0.1.1",
"main": "lib/index.js",
"module": "esm/index.js",
"unpkg": "dist/index.umd.min.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"esm",
"src",
"dist",
"README.md"
],
"sideEffects": [
"./esm/index.js"
],
"scripts": {
"dev": "vite",
"fix": "prettier --write src __tests__",
Expand All @@ -18,6 +22,7 @@
"test:format": "prettier --check src __tests__",
"build:cjs": "rimraf ./lib && tsc --module commonjs --outDir lib",
"build:esm": "rimraf ./esm && tsc --module ESNext --outDir esm",
"build:umd": "rimraf ./dist && rollup -c",
"build": "run-p build:*"
},
"dependencies": {
Expand All @@ -28,17 +33,24 @@
"@antv/util": "^3.3.5"
},
"peerDependencies": {
"@antv/g2": "^5.1.5"
"@antv/g": "^5.18.19",
"@antv/g2": "^5.1.8"
},
"devDependencies": {
"@types/d3-array": "3.0.5",
"@antv/g2": "^5.1.5",
"@antv/g": "^5.18.19",
"@antv/g2": "^5.1.8",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.3",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"rollup": "^3.29.2",
"typescript": "^5.2.2",
"vite": "^4.3.9",
"vitest": "^0.34.2"
},
"repository": "https://github.com/antvis/g2-extentions.git"
"repository": "https://github.com/antvis/g2-extensions.git"
}
51 changes: 51 additions & 0 deletions 3d/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { readFileSync } from "fs";

export default createConfig({
pkg: JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")),
umdName: "G2.Extension3D",
external: ["@antv/g2"],
globals: {
"@antv/g2": "window.G2",
},
});

function createConfig({ pkg, external = [], umdName = "", globals = {}, plugins = [] }) {
const sharedPlugins = [
...plugins,
nodeResolve({
mainFields: ["module", "browser", "main"],
extensions: [".js", ".jsx", ".ts", ".tsx", ".es6", ".es", ".mjs"],
}),
commonjs(),
typescript({ sourceMap: true }),
];

return [
{
input: "src/index.ts",
output: {
format: "umd",
file: pkg.unpkg,
name: umdName,
globals,
sourcemap: true,
},
external,
plugins: [
...sharedPlugins,
terser({
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}),
],
},
];
}
3 changes: 3 additions & 0 deletions 3d/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { runtime } from "@antv/g";
import { Interval3D } from "./mark/interval3D";
import { Point3D } from "./mark/point3D";
import { Line3D } from "./mark/line3D";
import { Cartesian3D } from "./coordinate/coordinate3D";
import { AxisZ } from "./component/axisZ";

runtime.enableCSSParsing = false;

export function threedlib() {
return {
"coordinate.cartesian3D": Cartesian3D,
Expand Down
6 changes: 4 additions & 2 deletions 3d/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"skipLibCheck": true,
"sourceRoot": "src",
"baseUrl": "src",
"resolveJsonModule": true
"resolveJsonModule": true,
"outDir": "./"
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"vite": "^4.3.9",
"vitest": "^0.34.2"
},
"repository": "https://github.com/antvis/g2-extentions.git"
"repository": "https://github.com/antvis/g2-extensions.git"
}

0 comments on commit 8ce5c5b

Please sign in to comment.