This guide illustrates how to consume vtk.js by way of transpiling. Please note that this method is discouraged, and it is recommended instead to follow the modern approach outlined in the introduction.
Which package to use
In order to take the transpilation approach, you must use the vtk.js
package instead of @kitware/vtk.js
. This will also impact your imports; imports will now be prefixed with vtk.js/Sources
, as shown below.
-import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer'; |
Transpiling vtk.js code
Make sure that the following packages are dependencies of your project:
npm install autoprefixer @babel/preset-env |
We primarily support webpack for transpiling vtk.js. The generic structure of the webpack structure is listed below, with comments.
// Required in order to build vtk.js alongside your project |
With vue-cli
If you are using vue-cli
, then you will need to have the following vue.config.js
:
const vtkChainWebpack = require('vtk.js/Utilities/config/chainWebpack'); |
with create-react-app
If you are using create-react-app
or react-app-rewired
, you will need to override the default build config. Specifically, there is a file-loader
rule that outputs assets to static/media/*
. In order for vtk.js glsl files to not be split out (since vtk.js does dynamic shader generation), you will need to add an exclude condition to that file-loader
, like so:
{ |