Skip to content

Commit 2834944

Browse files
authored
fix: Setup the dynamic import so it is separate from other packages (#113)
* fix: Setup the dynamic import so it is separate from other packages The default setup for dynamic import was such that the libraries would overlap with other libraries having the same names, which caused version mismatches when using the dynamic import version. This change makes the path separate. As well, it allows a named load for the library, which means the library can actually be used natively in the browser again, fixing issues with deployment standalone. * Add access to a few internals so that external features work
1 parent 587f11c commit 2834944

File tree

5 files changed

+90
-67
lines changed

5 files changed

+90
-67
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ Note that the *dicom-microscopy-viewer* package is **not** a viewer application,
3030
Below is an example for the most basic usage: a web page that displays a collection of DICOM VL Whole Slide Microscopy Image instances of a digital slide.
3131
For more advanced usage, take a look at the [Slim](https://github.com/imagingdatacommons/slim) viewer.
3232

33+
## Packaging
34+
35+
The library is packaged as two different builds, one using dynamic import, and the other bundling into one
36+
larger library. The dynamic import version uses a public path of `/dicom-microscopy-viewer/` so that they can be used by simply adding an alias to the appropriate version, and then deploying that version. In a straight web application, this can be loaded as:
37+
38+
```javascript
39+
const DICOMMicroscopyViewer = (await('/dicom-microscopy-viewer/dicomMicroscopyViewer.min.js')).default
40+
```
41+
42+
The point of using the sub-directory here is to isolate the dependencies that unique to `dicom-microscopy-viewer`.
43+
3344
### Basic usage
3445

3546
The viewer can be embedded in any website, one only needs to

config/webpack/webpack-dynamic-import.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const merge = require('./merge')
33
const rootPath = process.cwd()
44
const baseConfig = require('./webpack-base')
55
const TerserPlugin = require('terser-webpack-plugin')
6-
const outputPath = path.join(rootPath, 'dist', 'dynamic-import')
6+
const outputPath = path.join(rootPath, 'dist', 'dynamic-import', 'dicom-microscopy-viewer')
77

88
const prodConfig = {
99
mode: 'production',
@@ -12,11 +12,15 @@ const prodConfig = {
1212
},
1313
output: {
1414
path: outputPath,
15-
libraryTarget: 'umd',
16-
globalObject: 'this',
17-
filename: '[name].min.js'
15+
library: {
16+
name: 'dicomMicroscopyViewer',
17+
type: 'window',
18+
},
19+
filename: '[name].min.js',
20+
publicPath: '/dicom-microscopy-viewer/',
1821
},
1922
optimization: {
23+
// minimize: false,
2024
minimizer: [
2125
new TerserPlugin({
2226
parallel: true

package-lock.json

Lines changed: 67 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@babel/plugin-transform-runtime": "^7.15.0",
5656
"@babel/preset-env": "^7.16",
5757
"@babel/runtime-corejs3": "^7.15.4",
58-
"@webpack-cli/serve": "^1.5.2",
5958
"babel-eslint": "10.1.0",
6059
"babel-jest": "27.5",
6160
"babel-loader": "^8.2.3",
@@ -72,7 +71,7 @@
7271
"terser-webpack-plugin": "^5.2.2",
7372
"webpack": "^5.68",
7473
"webpack-bundle-analyzer": "^4.4.2",
75-
"webpack-cli": "^4.9",
74+
"webpack-cli": "^5.1.4",
7675
"webpack-dev-server": "^4.9.0",
7776
"worker-loader": "^3.0.8"
7877
},

src/viewer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ function _getColorPaletteStyleForPointLayer ({
686686
return { color: expression }
687687
}
688688

689-
const _affine = Symbol('affine')
689+
const _affine = Symbol.for('affine')
690690
const _affineInverse = Symbol('affineInverse')
691691
const _annotationManager = Symbol('annotationManager')
692692
const _annotationGroups = Symbol('annotationGroups')
@@ -697,8 +697,8 @@ const _drawingLayer = Symbol('drawingLayer')
697697
const _drawingSource = Symbol('drawingSource')
698698
const _features = Symbol('features')
699699
const _imageLayer = Symbol('imageLayer')
700-
const _interactions = Symbol('interactions')
701-
const _map = Symbol('map')
700+
const _interactions = Symbol.for('interactions')
701+
const _map = Symbol.for('map')
702702
const _mappings = Symbol('mappings')
703703
const _metadata = Symbol('metadata')
704704
const _opticalPaths = Symbol('opticalPaths')

0 commit comments

Comments
 (0)