Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use minified Cesium in Node.js unless NODE_ENV=development #7514

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ script:

- npm --silent run test -- --browsers FirefoxHeadless --failTaskOnError --webgl-stub --release --suppressPassed

- node index.js
- NODE_ENV=development node index.js

- NODE_ENV=production node index.js

- npm --silent run cloc
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Change Log
* Added a [new Sandcastle example](https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Time%20Dynamic%20Wheels.html) on using `nodeTransformations` to rotate a model's wheels based on its velocity. [#7361](https://github.com/AnalyticalGraphicsInc/cesium/pull/7361)
* Added `EllipsoidRhumbLine` class as a rhumb line counterpart to `EllipsoidGeodesic`. [#7484](https://github.com/AnalyticalGraphicsInc/cesium/pull/7484)
* Added rhumb line support to `PolygonGeometry`, `PolygonOutlineGeometry`, `PolylineGeometry`, `GroundPolylineGeometry`, and `SimplePolylineGeometry`. [#7492](https://github.com/AnalyticalGraphicsInc/cesium/pull/7492)
* When using Cesium in Node.js, we now use the combined and minified version for improved performance unless `NODE_ENV` is specifically set to `development`.
* Improved the performance of `QuantizedMeshTerrainData.interpolateHeight`. [#7508](https://github.com/AnalyticalGraphicsInc/cesium/pull/7508)

##### Fixes :wrench:
Expand Down
14 changes: 10 additions & 4 deletions Source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ require([
], function(
Cesium) {
'use strict';
/*global self*/
var scope = typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {};

scope.Cesium = Cesium;
/*global self,global*/
if (typeof window !== 'undefined') {
window.Cesium = Cesium;
} else if (typeof self !== 'undefined') {
self.Cesium = Cesium;
} else if (typeof global !== 'undefined') {
global.Cesium = Cesium;
} else {
console.log('Unable to load Cesium.');
}
}, undefined, true);
37 changes: 30 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
/*eslint-env node*/
/*eslint-env node,es6*/
'use strict';

var path = require('path');
var requirejs = require('requirejs');

//In explicit development mode, use un-optimized requirejs modules for improved error checking.
if (process.env.NODE_ENV === 'development') {
requirejs.config({
paths: {
'Cesium': path.join(__dirname, 'Source')
},
nodeRequire: require
});
module.exports = requirejs('Cesium/Cesium');
return;
}

//In all other cases, use minified Cesium for performance.
requirejs.config({
paths : {
'Cesium' : path.join(__dirname, 'Source')
},
nodeRequire : require
});
paths: {
'Cesium': path.join(__dirname, 'Build/Cesium/Cesium')
},
nodeRequire: require
});

const hadCesiumProperty = global.hasOwnProperty('Cesium');
const oldCesium = global.Cesium;

requirejs('Cesium');
module.exports = global.Cesium;

module.exports = requirejs('Cesium/Cesium');
if (hadCesiumProperty) {
global.Cesium = oldCesium;
} else {
delete global.Cesium;
}