Skip to content

Commit 4f64d78

Browse files
authored
Support local-math env option (visgl#5737)
Implements visgl#5736, adding a --env.local-math option to the `start-local` scripts to use local version of math.gl
1 parent 89301ae commit 4f64d78

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ If you consider opening a PR, here is some documentation to get you started:
3333
- vis.gl [developer process](https://www.github.com/visgl/tsc/tree/master/developer-process)
3434
- [deck.gl API design guidelines](/dev-docs/deckgl-api-guidelines.md)
3535

36+
## Testing examples with modified deck.gl source
37+
38+
Each example can be run so that it is built against the deck.gl source code in this repo instead of building against the installed version of deck.gl. This enables using the examples to debug the main deck.gl library source.
39+
40+
To do so use the `yarn start-local` command present in each example's directory. See [webpack.config.local.js](https://github.com/visgl/deck.gl/blob/master/examples/webpack.config.local.js) for details.
41+
42+
### Working with other vis.gl dependencies
43+
44+
Deck.gl has a number of dependencies that fall under vis.gl, and there may be times when it is necessary to make a change in one of these.
45+
Thus for development it is necessary to checkout a copy of such a dependency and make local changes.
46+
47+
When running an example using `yarn start-local` you can use local version of [luma.gl](https://github.com/visgl/luma.gl/) or [math.gl](https://github.com/uber-web/math.gl) by appending the `--env.local-luma` or `--env.local-math` option.
48+
49+
### Specific module overrides
50+
51+
To get the local build of deck.gl to pick up the local code rather than the modules from npm, there are two important config files:
52+
53+
- [ocular-dev-tools.config.js](https://github.com/visgl/deck.gl/blob/master/ocular-dev-tools.config.js) - See [Ocular documentation for details](https://uber-web.github.io/docs/dev-tools)
54+
- [examples/webpack.config.local.js](https://github.com/visgl/deck.gl/blob/master/examples/webpack.config.local.js)
55+
56+
_Note that the configuration in `examples/webpack.config.local.js` will potentially override the ocular configuration._
3657

3758
## Community Governance
3859

examples/webpack.config.local.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
//
55
// This enables using the examples to debug the main deck.gl library source
66
// without publishing or npm linking, with conveniences such hot reloading etc.
7+
// To use a local copy of luma.gl or math.gl when using
8+
// `yarn start-local` use the following options:
9+
// --env.local-luma
10+
// --env.local-math
11+
//
12+
// To specify more fine-grained overrides you can add to the aliases
13+
// below. For example if you have the `loaders.gl` repo checked out at the same level as deck.gl and want to work with a local copy of the `mvt` module, you would add the following `alias` to the configuration:
14+
// `'@loaders.gl/mvt': resolve(__dirname, '../loaders.gl/modules/mvt/src')`
715

816
// avoid destructuring for older Node version support
917
const resolve = require('path').resolve;
@@ -16,7 +24,7 @@ const ALIASES = require('ocular-dev-tools/config/ocular.config')({
1624
}).aliases;
1725

1826
// Support for hot reloading changes to the deck.gl library:
19-
function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma) {
27+
function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma, linkToMath) {
2028
const LUMA_LINK_ALIASES = {
2129
'@luma.gl/constants': `${ROOT_DIR}/../luma.gl/modules/constants/src`,
2230
'@luma.gl/core': `${ROOT_DIR}/../luma.gl/modules/core/src`,
@@ -45,6 +53,27 @@ function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma) {
4553
// console.warn(JSON.stringify(LUMA_ALIASES, null, 2)); // uncomment to debug config
4654
// require('fs').writeFileSync('/tmp/ocular.log', JSON.stringify(config, null, 2));
4755

56+
const MATH_ALIASES = {};
57+
if (linkToMath) {
58+
const MATH_MODULES = [
59+
'core',
60+
'culling',
61+
'geoid',
62+
'geospatial',
63+
'main',
64+
'mercator',
65+
'polygon',
66+
'proj4',
67+
'sun',
68+
'web'
69+
];
70+
for (const module of MATH_MODULES) {
71+
MATH_ALIASES[`@math.gl/${module}`] = `${ROOT_DIR}/../math.gl/modules/${module}/src`;
72+
}
73+
} else {
74+
MATH_ALIASES['math.gl'] = resolve(LIB_DIR, './node_modules/math.gl');
75+
}
76+
4877
return {
4978
// TODO - Uncomment when all examples use webpack 4 for faster bundling
5079
// mode: 'development',
@@ -61,11 +90,10 @@ function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma) {
6190
resolve: {
6291
// mainFields: ['esnext', 'module', 'main'],
6392

64-
alias: Object.assign({}, ALIASES, LUMA_ALIASES, {
93+
alias: Object.assign({}, ALIASES, LUMA_ALIASES, MATH_ALIASES, {
6594
// Use luma.gl installed in parallel with deck.gl
6695
// Important: ensure shared dependencies come from the main node_modules dir
6796
// Versions will be controlled by the deck.gl top level package.json
68-
'math.gl': resolve(LIB_DIR, './node_modules/math.gl'),
6997
'viewport-mercator-project': resolve(LIB_DIR, './node_modules/viewport-mercator-project'),
7098
react: resolve(LIB_DIR, './node_modules/react')
7199
})
@@ -94,8 +122,8 @@ function makeLocalDevConfig(EXAMPLE_DIR = LIB_DIR, linkToLuma) {
94122
};
95123
}
96124

97-
function addLocalDevSettings(config, exampleDir, linkToLuma) {
98-
const LOCAL_DEV_CONFIG = makeLocalDevConfig(exampleDir, linkToLuma);
125+
function addLocalDevSettings(config, exampleDir, linkToLuma, linkToMath) {
126+
const LOCAL_DEV_CONFIG = makeLocalDevConfig(exampleDir, linkToLuma, linkToMath);
99127
config = Object.assign({}, LOCAL_DEV_CONFIG, config);
100128
config.resolve = Object.assign({}, LOCAL_DEV_CONFIG.resolve, config.resolve || {});
101129
config.resolve.alias = config.resolve.alias || {};
@@ -115,12 +143,12 @@ module.exports = (config, exampleDir) => env => {
115143
}
116144

117145
if (env.local) {
118-
config = addLocalDevSettings(config, exampleDir, env['local-luma']);
146+
config = addLocalDevSettings(config, exampleDir, env['local-luma'], env['local-math']);
119147
}
120148

121149
// npm run start-es6 does not transpile the lib
122150
if (env && env.es6) {
123-
config = addLocalDevSettings(config, exampleDir, env['local-luma']);
151+
config = addLocalDevSettings(config, exampleDir, env['local-luma'], env['local-math']);
124152
}
125153

126154
if (env && env.production) {

0 commit comments

Comments
 (0)