开发:增加Roullup打包api功能

rm_cache_rendertype
ChenX 4 years ago
parent af9988d75b
commit db3cbee29f

3
.gitignore vendored

@ -62,3 +62,6 @@ typings/
/dist*
/package-lock.json
yarn.lock
#导出的WebCADApi
api

@ -0,0 +1,11 @@
{
"name": "cadapi",
"version": "0.0.3",
"description": "",
"main": "api.esm.js",
"module": "api.esm.js",
"types": "types/api.d.ts",
"private": true,
"author": "cx",
"license": "ISC"
}

@ -0,0 +1,28 @@
{
"compilerOptions": {
"sourceMap": true,
"module": "CommonJS",
"target": "ES2019",
"noLib": false,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowJs": true,
"outDir": "./dist",
"lib": [
"esnext",
"dom"
],
"types": [
"node",
"webpack-env",
"webpack-dev-server",
"jest"
],
"jsx": "react",
"experimentalDecorators": true
},
"include": [
"./src/**/*"
]
}

@ -0,0 +1,53 @@
//npm run api
//npm run apid
//把es.js的mobx的删除了.
//删除Require(*.vs)
//这个现在已经变成了官方插件,但是现在有BUG,等它修复好,就可以改成这个 https://github.com/rollup/plugins/issues/243
// import typescript from '@rollup/plugin-typescript';
//参考:https://juejin.im/post/6844903968766689294
import typescript from "rollup-plugin-typescript";
import sourceMaps from "rollup-plugin-sourcemaps";
// import dts from "rollup-plugin-dts";
import shader from 'rollup-plugin-shader';
export default [{
input: "./src/api.ts",
plugins: [
typescript({
exclude: "node_modules/**",
typescript: require("typescript")
}),
sourceMaps(),
shader({
// 这个不行(不能搞定require(.vs)) 必须手动删除
// All match files will be parsed by default,
// but you can also specifically include/exclude files
include: ['**/*.vs', '**/*.fs'], // default: [ '**/*.glsl', '**/*.vs', '**/*.fs' ]
exclude: ['node_modules/**'],
// specify whether to remove comments
removeComments: true, // default: true
})
],
output: [
{
format: "cjs",
file: "./api/api.cjs.js",
sourcemap: true
},
{
format: "es",
file: "./api/api.esm.js",
sourcemap: true
}
]
},
// {
// 这个也不能用,因为它会把所有的给依赖进来,而且因为生成的d.ts有问题
// input: "./api/types/src/api.d.ts",
// output: [{ file: "./api/types/api.d.ts", format: "es" }],
// plugins: [dts()],
// },
];

@ -0,0 +1,67 @@
import * as path from 'path';
import * as webpack from 'webpack';
import { merge } from 'webpack-merge';
import WebpackBar from 'webpackbar';
const TS_LOADER = [
{ loader: 'cache-loader', options: { cacheDirectory: "node_modules/.cache_loader" } },
{
loader: 'ts-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
}
];
const config: webpack.Configuration = merge(
{
// mode: "production",
mode: "development",
entry: "./src/api.ts",
stats: {
modules: true,
},
devtool: "source-map",
externals: {
'three': "THREE"
},
//输出设置
output: {
filename: "webcad-api.js",
path: path.resolve(__dirname, "../dist/umd/"),
library: "webcad-api",
libraryTarget: "umd"
},
resolve: {
extensions: [".ts", ".tsx", ".js", "json"]
},
module: {
rules: [
{
test: /\.worker\.ts$/,
exclude: /node_modules/,
use: [
{ loader: 'worker-loader', },
...TS_LOADER
]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: TS_LOADER,
},
{
test: /\.(glsl|vs|fs)$/,
loader: 'shader-loader'
}
]
},
plugins: [
new WebpackBar()
],
node: false
}
);
export default config;

@ -9,6 +9,9 @@
"buildview": "webpack --config dll.config.js &&webpack --config web-cad-view.config.ts",
"dll": "webpack --config ./config/webpack.dll.ts",
"build": "webpack --config ./config/webpack.prod.ts && ts-node ./utils/log.ts && ts-node ./utils/publish.ts",
"api-test": "webpack --config ./config/webcadapi.umd.config.ts --display-modules",
"api": "rollup --config ./config/api.rollup.config.js",
"apid": "tsc --declaration --emitDeclarationOnly --declarationMap --declarationDir ./api/types --project apitsconfig.json",
"test": "jest",
"testu": "jest -u",
"testw": "jest --watchAll",
@ -20,6 +23,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-typescript": "^6.0.0",
"@types/html-webpack-plugin": "^3.2.3",
"@types/jest": "^26.0.13",
"@types/node": "^14.10.0",
@ -33,6 +37,7 @@
"@types/webpack-dev-server": "^3.11.0",
"@types/webpack-env": "^1.15.2",
"@types/webpack-merge": "^4.1.5",
"@wessberg/rollup-plugin-ts": "^1.3.4",
"add-asset-html-webpack-plugin": "^3.1.3",
"autoresponsive-react": "^1.1.31",
"cache-loader": "^4.1.0",
@ -56,15 +61,22 @@
"request-promise-native": "^1.0.9",
"required-loader": "^1.3.16",
"resize-observer-polyfill": "^1.5.1",
"rollup": "^2.28.1",
"rollup-plugin-dts": "^1.4.13",
"rollup-plugin-shader": "0.0.3",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup-plugin-typescript": "^1.0.1",
"shader-loader": "^1.3.1",
"source-map-loader": "^1.1.0",
"style-loader": "^1.2.1",
"terser-webpack-plugin": "^4.1.0",
"ts-declaration-webpack-plugin": "^1.2.3",
"ts-jest": "^26.3.0",
"ts-loader": "^8.0.3",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.2",
"tslib": "^2.0.1",
"typescript": "^4.0.3",
"url-loader": "^4.1.0",
"wallaby-webpack": "^3.9.15",
"webpack": "^4.44.1",

@ -17,18 +17,6 @@ export const FileFormatReg = /^\[(\d+,){5}[(true)|(false)].+\]$/;
/**扣除封边是否相连和连接共用精度 */
export const LINK_FUZZ = 1e-3;
export async function draw(en: Entity | Entity[] | Object3D)
{
let app = (await import("../ApplicationServices/Application")).app;
if (en instanceof Object3D)
app.Viewer.Scene.add(en);
else if (en instanceof Entity)
app.Database.ModelSpace.Append(en);
else
for (let e of en)
app.Database.ModelSpace.Append(e);
}
export function IsNumber(keyCode: number)
{
return (keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105);

@ -0,0 +1,15 @@
import { Object3D } from "three";
import { Entity } from "../DatabaseServices/Entity/Entity";
export async function draw(en: Entity | Entity[] | Object3D)
{
let app = (await import("../ApplicationServices/Application")).app;
if (en instanceof Object3D)
app.Viewer.Scene.add(en);
else if (en instanceof Entity)
app.Database.ModelSpace.Append(en);
else
for (let e of en)
app.Database.ModelSpace.Append(e);
}

@ -5,7 +5,7 @@ import ResizeObserver from 'resize-observer-polyfill';
import { app, ApplicationService } from '../../ApplicationServices/Application';
import { KeyBoard } from '../../Common/KeyEnum';
import { _LogInjectFunctions } from '../../Common/Log';
import { draw } from '../../Common/Utils';
import { draw } from "../../Common/draw";
import { ZINDEX } from '../../Common/ZIndex';
import { registerCommand } from '../../Editor/CommandRegister';
import { CameraControlBtn, CameraControlBtnStore } from '../Components/CameraControlButton/CameraControlBtn';

@ -0,0 +1 @@
export * from "./DatabaseServices/Entity/Polyline";
Loading…
Cancel
Save