Skip to content

Commit ae7ed78

Browse files
committed
build(annotation): move from rollup to vite
1 parent d16be07 commit ae7ed78

File tree

12 files changed

+130
-166
lines changed

12 files changed

+130
-166
lines changed

libs/annotation/.eslintrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["../../.eslintrc.json"],
2+
"extends": ["../.eslintrc.json"],
33
"ignorePatterns": ["!**/*"],
44
"overrides": [
55
{
@@ -21,7 +21,7 @@
2121
"@nx/dependency-checks": [
2222
"error",
2323
{
24-
"ignoredFiles": ["{projectRoot}/rollup.config.{js,ts,mjs,mts}"]
24+
"ignoredFiles": ["{projectRoot}/vite.config.{js,ts,mjs,mts}"]
2525
}
2626
]
2727
}

libs/annotation/.swcrc

Lines changed: 0 additions & 31 deletions
This file was deleted.
File renamed without changes.

libs/annotation/README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,75 @@
1-
[GO TO README HERE](./src/README.md)
1+
# @octra/annotation <a href="https://www.npmjs.com/package/@octra/annotation"><img alt="npm" src="https://img.shields.io/npm/v/@octra/annotation"></a>
2+
3+
This library offers all annotation related classes and functions used by Octra. It uses AnnotJSON file format as base
4+
model. Here you can also find all Annotation converters used by [Octra](https://github.com/IPS-LMU/octra).
5+
6+
## Installation
7+
8+
### ESM, CJS, TS definitions & UMD (optional)
9+
10+
````shell
11+
npm install --save @octra/annotation
12+
````
13+
14+
### UMD Bundle (for Vanilla JS)
15+
16+
You have two options to install this package und use it as UMD:
17+
18+
a) Install via NPM and reference local files (no internet connection needed om production).
19+
````html
20+
<script type="application/javascript" src="node_modules/@octra/annotation/index.umd.js"></script>
21+
````
22+
23+
b) Reference remote file (internet connection needed on production).
24+
````html
25+
<script type="application/javascript" src="https://unpkg.com/@octra/annotation/index.umd.js"></script>
26+
````
27+
28+
[See full example here](https://github.com/IPS-LMU/octra/blob/main/apps/web-components-demo/index.html)
29+
30+
## Use
31+
32+
### Import
33+
34+
#### ESM, Typescript
35+
36+
Import the classes and functions from `@octra/annotation`. For example
37+
38+
````typescript
39+
import { Level } from "@octra/annotation";
40+
41+
const annotation = new OctraAnnotation();
42+
const level = annotation.addLevel(new OctraAnnotation.createSegmentLevel("OCTRA_1"));
43+
annotation.addItemToCurrentLevel(new SampleUnit(123456, 22050), [
44+
new OLabel(
45+
"OCTRA_1",
46+
"hello world"
47+
)
48+
]);
49+
````
50+
51+
#### UMD Bundle
52+
53+
All functions and classes are available via global scope `OctraAnnotation`. For example:
54+
55+
```javascript
56+
/*
57+
make sure that you have injected the umd bundle as described before.
58+
*/
59+
const annotation = new OctraAnnotation.OctraAnnotation();
60+
const level = annotation.addLevel(new OctraAnnotation.OctraAnnotation.createSegmentLevel("OCTRA_1"));
61+
annotation.addItemToCurrentLevel(new OctraAnnotation.SampleUnit(123456, 22050), [
62+
new OctraAnnotation.OLabel(
63+
"OCTRA_1",
64+
"hello world"
65+
)
66+
]);
67+
```
68+
69+
### API
70+
71+
You can find more information about classes and functions of `@octra/annotation` [here](https://ips-lmu.github.io/octra/modules/_octra_annotation.html).
72+
73+
### Changelog
74+
75+
[Go to changelog](https://github.com/IPS-LMU/octra/blob/main/libs/annotation/CHANGELOG.md)

libs/annotation/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"url": "https://github.com/IPS-LMU/octra"
2121
},
2222
"type": "commonjs",
23-
"main": "./index.cjs",
24-
"module": "./index.js",
25-
"typings": "./src/index.d.ts"
23+
"main": "./index.js",
24+
"module": "./index.mjs",
25+
"typings": "./index.d.ts"
2626
}

libs/annotation/project.json

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,22 @@
11
{
22
"name": "annotation",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4-
"sourceRoot": "libs/annotation/src",
4+
"sourceRoot": "annotation/src",
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "@nx/rollup:rollup",
8+
"executor": "@nx/vite:build",
99
"outputs": ["{options.outputPath}"],
10+
"generateExportsField": true,
1011
"options": {
11-
"rollupConfig": "libs/annotation/rollup.cjs",
12-
"outputPath": "dist/libs/annotation",
13-
"main": "libs/annotation/src/index.ts",
14-
"tsConfig": "libs/annotation/tsconfig.lib.json",
15-
"external": ["@octra/media", "@octra/utilities"],
16-
"project": "libs/annotation/package.json",
17-
"compiler": "tsc",
18-
"format": ["cjs", "esm"],
19-
"assets": [
20-
"libs/annotation/src/LICENSE.txt",
21-
"libs/annotation/src/README.md"
22-
]
12+
"outputPath": "dist/libs/annotation"
2313
}
2414
},
25-
"bundle": {
26-
"executor": "@nx/webpack:webpack",
27-
"outputs": ["{options.outputPath}"],
28-
"options": {
29-
"babelUpwardRootMode": true,
30-
"externalDependencies": ["@octra/media", "@octra/utilities"],
31-
"libraryName": "OctraAnnotation",
32-
"libraryTargets": ["umd"],
33-
"index": "",
34-
"tsConfig": "libs/annotation/tsconfig.lib.json",
35-
"main": "libs/annotation/src/index.ts",
36-
"outputPath": "dist/libs/annotation/bundles",
37-
"compiler": "tsc",
38-
"optimization": true,
39-
"extractLicenses": true,
40-
"runtimeChunk": false,
41-
"vendorChunk": false,
42-
"generateIndexHtml": false,
43-
"commonChunk": false,
44-
"namedChunks": false,
45-
"webpackConfig": "webpack.config.js"
46-
},
47-
"dependsOn": ["build"]
48-
},
4915
"lint": {
5016
"executor": "@nx/linter:eslint",
5117
"outputs": ["{options.outputFile}"],
5218
"options": {
53-
"lintFilePatterns": [
54-
"libs/annotation/**/*.ts",
55-
"libs/annotation/package.json"
56-
]
19+
"lintFilePatterns": ["annotation/**/*.ts", "annotation/package.json"]
5720
}
5821
},
5922
"version": {

libs/annotation/rollup.cjs

Lines changed: 0 additions & 9 deletions
This file was deleted.

libs/annotation/src/README.md

Lines changed: 0 additions & 75 deletions
This file was deleted.

libs/annotation/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"noFallthroughCasesInSwitch": true,
1111
"allowSyntheticDefaultImports": true
1212
},
13+
"files": [],
1314
"include": [],
1415
"references": [
1516
{

libs/annotation/tsconfig.lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"outDir": "../../dist/out-tsc",
55
"declaration": true,
6-
"types": ["node"]
6+
"types": ["node", "vite/client"]
77
},
88
"include": ["src/**/*.ts"],
99
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]

libs/annotation/vite.config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vite';
3+
import dts from 'vite-plugin-dts';
4+
import * as path from 'path';
5+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6+
7+
export default defineConfig({
8+
cacheDir: '../node_modules/.vite/annotation',
9+
10+
plugins: [
11+
dts({
12+
entryRoot: 'src',
13+
tsConfigFilePath: path.join(__dirname, 'tsconfig.lib.json'),
14+
skipDiagnostics: true,
15+
}),
16+
nxViteTsPaths(),
17+
],
18+
19+
// Uncomment this if you are using workers.
20+
// worker: {
21+
// plugins: [ nxViteTsPaths() ],
22+
// },
23+
24+
// Configuration for building your library.
25+
// See: https://vitejs.dev/guide/build.html#library-mode
26+
build: {
27+
lib: {
28+
// Could also be a dictionary or array of multiple entry points.
29+
entry: 'src/index.ts',
30+
name: 'OctraAnnotation',
31+
fileName: 'index',
32+
// Change this to the formats you want to support.
33+
// Don't forget to update your package.json as well.
34+
formats: ['es', 'cjs', 'umd', 'iife'],
35+
},
36+
rollupOptions: {
37+
// External packages that should not be bundled into your library.
38+
external: [],
39+
},
40+
},
41+
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"build:assets": "nx build assets",
1818
"build:web-components": "nx build ngx-components && nx build web-components --outputHashing none && node prepare_web-components.js",
1919
"build:watch:deploy": "nx build octra --configuration=public-development --base-href=/apps/octra/octra-dev/ --outputPath ./deploy --watch",
20-
"release:lib:annotation": "nx bundle annotation && nx run annotation:version --push",
21-
"publish:lib:annotation": "nx bundle annotation && nx npm annotation",
20+
"release:lib:annotation": "node runner.js build:lib annotation && nx run annotation:version --push",
21+
"publish:lib:annotation": "node runner.js build:lib annotation && nx npm annotation",
2222
"release:lib:assets": "nx run assets:version --releaseAs=patch --push",
2323
"publish:lib:assets": "nx npm assets",
2424
"release:lib:json-sets": "nx bundle json-sets && nx run json-sets:version --push",

0 commit comments

Comments
 (0)