Skip to content

Commit

Permalink
Merge pull request #7514 from AnalyticalGraphicsInc/node-env
Browse files Browse the repository at this point in the history
Use minified Cesium in Node.js unless NODE_ENV=development
  • Loading branch information
Hannah authored Jan 31, 2019
2 parents 6f5dd4f + 2b4cc47 commit a03edeb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
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;
}

0 comments on commit a03edeb

Please sign in to comment.