Skip to content

Commit

Permalink
chore(webpack): Use v5 asset modules over loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Sep 23, 2021
1 parent f362ebe commit f400eb6
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Documentation/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
},
{
test: /\\.svg$/,
use: [{ loader: 'raw-loader' }],
type: 'asset/source',
},
{
test: /\\.worker\\.js$/,
Expand All @@ -78,7 +78,7 @@ module.exports = {
},
],
},
{ test: /\\.(png|jpg)$/, use: 'url-loader?limit=81920' },
{ test: /\\.(png|jpg)$/, type: 'asset' },
{ test: /\\.html$/, loader: 'html-loader' },
{ test: /\\.cjson$/, loader: 'hson-loader' },
{ test: /\\.hson$/, loader: 'hson-loader' },
Expand Down
2 changes: 1 addition & 1 deletion Documentation/content/docs/develop_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The library can be built with webpack automatically. Webpack can either gather a

## Building vtk.js

In order to build the library you can run `npm run build` for quick development usage or `npm run build:release` for production usage.
In order to build the library you can run `npm run dev` for quick development usage or `npm run build` for production usage.

Either of these commands will generate a `dist/vtk.js` file that can then be used as an external script.

Expand Down
10 changes: 7 additions & 3 deletions Documentation/content/docs/intro_vtk_as_es6_dependency.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ title: Using vtk.js as an ES6 dependency

This guide illustrates how to consume vtk.js as an ES dependency.

This document was last updated with the following package versions:
- `@kitware/vtk.js@v19`
- `webpack@v5`

## Starting a new vtk.js project

There are several ways to start a new vtk.js project. Below lists a few ways you can begin using vtk.js with your favorite project build tool.
Expand Down Expand Up @@ -111,8 +115,8 @@ var cssRules = require('vtk.js/Utilities/config/dependency.js').webpack.css.rule
module: {
rules: [
{ test: /\.html$/, loader: 'html-loader' },
{ test: /\.(png|jpg)$/, use: 'url-loader?limit=81920' },
{ test: /\.svg$/, use: [{ loader: 'raw-loader' }] },
{ test: /\.(png|jpg)$/, type: 'asset' },
{ test: /\.svg$/, type: 'asset/source' },
].concat(vtkRules, cssRules),
},

Expand All @@ -121,4 +125,4 @@ var cssRules = require('vtk.js/Utilities/config/dependency.js').webpack.css.rule

Another possible issue is the fact that some relative import can not be resolved. In which case, you should copy those files to your local `./src/` directory and fix the actual import path.

And if you didn't skip any piece you should be allset and ready to run that new code base.
And if you didn't skip any piece you should be all set and ready to run that new code base.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ In general VTK tries to be as portable as possible; the specific configurations

vtk.js supports the following development environments:

- Node 10+
- Node 12+
- NPM 6+

and we use [@babel/preset-env](https://www.npmjs.com/package/@babel/preset-env) with the [defaults](https://github.com/Kitware/vtk-js/blob/master/.browserslistrc) set of [browsers target](https://browserl.ist/?q=defaults).
Expand Down
2 changes: 1 addition & 1 deletion Utilities/config/rules-examples.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = [
{ test: /\.(png|jpg)$/, use: 'url-loader?limit=81920' },
{ test: /\.(png|jpg)$/, type: 'asset' },
{ test: /\.html$/, loader: 'html-loader' },
{ test: /\.cjson$/, loader: 'hson-loader' },
{ test: /\.hson$/, loader: 'hson-loader' },
Expand Down
11 changes: 9 additions & 2 deletions Utilities/config/rules-tests.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports = [
{ test: /canvas.node/, loader: 'ignore-loader' },
{ test: /\.cjson$/, loader: 'hson-loader' },
{ test: /test[^\.]*\.(png|jpg)$/, use: 'url-loader?limit=1048576' },
{
test: /test[^\.]*\.(png|jpg)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 1024 * 1024,
},
},
},
{ test: /\.glsl$/i, loader: 'shader-loader' },
{
test: /\.worker\.js$/,
Expand Down
2 changes: 1 addition & 1 deletion Utilities/config/rules-vtk.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = [
},
{
test: /\.svg$/,
use: [{ loader: 'raw-loader' }],
type: 'asset/source',
},
{
test: /\.worker\.js$/,
Expand Down
62 changes: 0 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"postcss-loader": "6.1.1",
"prettier": "2.4.0",
"process": "0.11.10",
"raw-loader": "4.0.2",
"rollup": "2.56.3",
"rollup-plugin-ignore": "1.0.10",
"rollup-plugin-polyfill-node": "0.7.0",
Expand All @@ -116,7 +115,6 @@
"tap-spec": "5.0.0",
"tape": "5.3.1",
"tape-catch": "1.0.6",
"url-loader": "4.1.1",
"webpack": "5.52.1",
"webpack-bundle-analyzer": "4.4.2",
"webpack-cli": "4.8.0",
Expand Down
2 changes: 1 addition & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function configureVtkRules() {
},
{
test: /\.svg$/,
use: [{ loader: 'raw-loader' }],
type: 'asset/source',
},
{
test: /\.worker\.js$/,
Expand Down

0 comments on commit f400eb6

Please sign in to comment.