-
Notifications
You must be signed in to change notification settings - Fork 160
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
Revised our public CesiumJS & webpack guide #28
Changes from 66 commits
5b74985
cf65181
d44239f
cd610d2
b3243bf
7111d30
e7b17fa
c0eb8b6
a7849c3
477fce6
60d0683
b5494b2
dde2b44
67025e8
e723825
a8c1867
dcfca51
75887f3
a180410
4deb9d8
b4d8d41
34dbfc2
5d7deb9
d702e46
3fa578b
f93b2e1
f778103
529b72b
a15c18e
ce4300f
8e1b362
e1087b1
02fd982
65a5b5b
0f1a9cc
bba8ff5
abafe58
b136ad7
5ca60be
a8669a5
da88a4d
72fe12d
c0b0dfc
1a216a4
78231bc
4877406
af71f1a
076ad35
e8db53a
21673a7
6207790
09f12e0
8058aea
308697a
073a8b9
833b653
277cb85
7f53ee2
02dfd9f
b489751
252fc4e
0a5d5dc
da0c686
e3dd1a9
22869b3
eabfe69
9426429
557f990
d764308
02379b4
ed102e7
6f8ca94
21804ab
d8cc595
c71cc23
2d70cdc
0cce7db
523f412
27abc22
0d77de6
73fa09d
1300b73
6e97a9d
d929d66
a117a63
6d8aa9c
d5a4474
1f31926
6f12f01
e605e06
5f40257
7cb9819
e972bac
eb02aac
ae53686
7de3fbd
1f31648
f0dea0c
83bab72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ node_js: | |
- '10' | ||
- '12' | ||
script: | ||
- npm run build | ||
- npm run release | ||
- npm run build |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,43 @@ | ||
{ | ||
"name": "cesium-webpack-example", | ||
"name": "cesiumjs-webpack-example", | ||
"version": "1.0.0", | ||
"description": "The minimal recomended setup for an app using Cesium with Webpack.", | ||
"main": "index.js", | ||
"homepage": "https://cesium.com/platform/cesiumjs/", | ||
"license": "Apache-2.0", | ||
"author": { | ||
"name": "Cesium GS, Inc.", | ||
"url": "https://cesium.com" | ||
}, | ||
"keywords": [ | ||
"cesium", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is nitpick-y, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No not at all! I think this is a great idea - I just added it back. |
||
"CesiumJS", | ||
"webpack", | ||
"example" | ||
], | ||
"author": { | ||
"name": "Cesium GS, Inc.", | ||
"url": "https://cesium.com" | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/CesiumGS/cesium-webpack-example.git" | ||
}, | ||
"homepage": "https://cesiumjs.org", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"cesium": "^1.63.1" | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "node_modules/.bin/webpack --config webpack.config.js", | ||
"start": "node_modules/.bin/webpack serve --config webpack.config.js --open" | ||
}, | ||
"devDependencies": { | ||
"copy-webpack-plugin": "^6.0.3", | ||
"css-loader": "^3.2.0", | ||
"html-webpack-plugin": "^3.2.0", | ||
"cesium": "^1.84.0", | ||
"copy-webpack-plugin": "^9.0.1", | ||
"css-loader": "^6.2.0", | ||
"html-webpack-plugin": "^5.3.2", | ||
"sass-loader": "^7.1.0", | ||
"strip-pragma-loader": "^1.0.0", | ||
"style-loader": "^1.0.0", | ||
"uglifyjs-webpack-plugin": "^2.2.0", | ||
"url-loader": "^2.2.0", | ||
"webpack": "^4.41.2", | ||
"webpack-cli": "^3.3.9", | ||
"webpack-dev-server": "^3.9.0" | ||
"style-loader": "^3.2.1", | ||
"url-loader": "^4.1.1", | ||
"webpack-cli": "^4.8.0", | ||
"webpack-dev-server": "^3.11.2" | ||
}, | ||
"scripts": { | ||
"build": "node_modules/.bin/webpack --config webpack.config.js", | ||
"start": "node_modules/.bin/webpack-dev-server --config webpack.config.js", | ||
"release": "node_modules/.bin/webpack --config webpack.release.config.js", | ||
"serve-release": "node_modules/.bin/webpack-dev-server --config webpack.release.config.js --content-base /dist" | ||
"dependencies": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there not only be one dependency
and all others are being |
||
"cesiumjs": "^1.10.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this. I was a little bit confused because we are using two different names to import CesiumJS - "cesium" and "cesiumjs" |
||
"es6": "^0.0.7", | ||
"release": "^6.3.0", | ||
"webpack": "^5.51.1" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all of these are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see where the other 3 dependencies (es6, querystring, release) are actually being used. Maybe I'm missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read through this thread for some context and added a commit with the update. We now do not have any "dependencies" - is that correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's my thinking, yes. The packaged version of this app would not need any of these packages installed to run. And, yes, please double check if all of these packages are being used, and if not, remove them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ggetz good point 😄 I just ran the command
However, when running |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> | ||
<title>Cesium + Webpack</title> | ||
</head> | ||
<body> | ||
<div id="cesiumContainer"></div> | ||
</body> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<div id="cesiumContainer"></div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { Ion, Viewer, createWorldTerrain, createOsmBuildings, Cartesian3, Math } from "../node_modules/cesium" | ||
import "../node_modules/cesium/Build/Cesium/Widgets/widgets.css"; | ||
|
||
import { Cesium3DTileset, createWorldTerrain, IonResource, Viewer } from 'cesium'; | ||
import "cesium/Build/Cesium/Widgets/widgets.css"; | ||
import "./css/main.css"; | ||
// Your access token can be found at: https://cesium.com/ion/tokens. | ||
// This is the default access token from your ion account | ||
Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJlYWE1OWUxNy1mMWZiLTQzYjYtYTQ0OS1kMWFjYmFkNjc5YzciLCJpZCI6NTc3MzMsImlhdCI6MTYyNzg0NTE4Mn0.XcKpgANiY19MC4bdFUXMVEBToBmqS8kuYpUlxJHYZxk'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this default token coming from? Are you adding the right documentation needed to cycle this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default token is coming from the CesiumJS Quickstart Guide. I think this is appropriate here, given that I am using the code from that guide. Please let me know if you would like me to make any edits here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then the comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just updated the wording for the Webpack tutorial. However, in that case, the wording for the CesiumJS quickstart guide is also incorrect and should be updated. |
||
|
||
// This is simplified version of Cesium's Getting Started tutorial. | ||
// See https://cesium.com/docs/tutorials/getting-started/ for more details. | ||
|
||
var viewer = new Viewer('cesiumContainer', { | ||
terrainProvider: createWorldTerrain() | ||
// Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID. | ||
const viewer = new Viewer('cesiumContainer', { | ||
terrainProvider: createWorldTerrain() | ||
}); | ||
|
||
var tileset = new Cesium3DTileset({ | ||
url: IonResource.fromAssetId(40866) | ||
}); | ||
// Add Cesium OSM Buildings, a global 3D buildings layer. | ||
viewer.scene.primitives.add(createOsmBuildings()); | ||
|
||
viewer.scene.primitives.add(tileset); | ||
viewer.zoomTo(tileset); | ||
// Fly the camera to San Francisco at the given longitude, latitude, and height. | ||
viewer.camera.flyTo({ | ||
destination : Cartesian3.fromDegrees(-122.4175, 37.655, 400), | ||
orientation : { | ||
heading : Math.toRadians(0.0), | ||
pitch : Math.toRadians(-15.0), | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
// The path to the CesiumJS source code | ||
const cesiumSource = 'node_modules/cesium/Source'; | ||
const cesiumWorkers = '../Build/Cesium/Workers'; | ||
const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
const path = require('path'); | ||
|
||
const webpack = require('webpack'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const CopyWebpackPlugin = require('copy-webpack-plugin'); | ||
|
||
module.exports = [{ | ||
mode: 'development', | ||
module.exports = { | ||
context: __dirname, | ||
entry: { | ||
app: './src/index.js' | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: path.resolve(__dirname, 'dist') | ||
filename: 'app.js', | ||
srothst1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
path: path.resolve(__dirname, 'dist'), | ||
sourcePrefix: '' | ||
}, | ||
devtool: 'eval', | ||
node: { | ||
// Resolve node module use of fs | ||
fs: "empty", | ||
Buffer: false, | ||
http: "empty", | ||
https: "empty", | ||
zlib: "empty" | ||
amd: { | ||
// Enable webpack-friendly use of require in Cesium | ||
toUrlUndefined: true | ||
}, | ||
resolve: { | ||
mainFields: ['module', 'main'] | ||
alias: { | ||
// CesiumJS module name | ||
cesium: path.resolve(__dirname, cesiumSource) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've defined the It's pretty atypical to define relative paths to dependencies in At first, I would have suggested omitting the
However, there's an issue when importing After testing this out myself, I think we should keep the above alias, but configure the Cesium's main module file so that Cesium can be resolved without a relative path. So in
and the first few lines of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not aware of the issue in the CesiumJS repo that you shared. It looks like @thw0rted offered to submit a PR that resolves at least some of the bugs. In the meantime, I just added a commit that implements the suggestions that you gave. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, instead of a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion! I believe that is captured in the issue I linked to above. While that change is out of the scope of this PR and repo, we can adjust this example if/when Cesium's |
||
} | ||
}, | ||
module: { | ||
rules: [{ | ||
test: /\.css$/, | ||
use: ['style-loader', 'css-loader'] | ||
use: [ 'style-loader', 'css-loader' ] | ||
}, { | ||
test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/, | ||
use: ['url-loader'] | ||
use: [ 'url-loader' ] | ||
}] | ||
}, | ||
plugins: [ | ||
|
@@ -42,20 +42,16 @@ module.exports = [{ | |
// Copy Cesium Assets, Widgets, and Workers to a static directory | ||
new CopyWebpackPlugin({ | ||
patterns: [ | ||
{ from: 'node_modules/cesium/Build/Cesium/Workers', to: 'Workers' }, | ||
{ from: 'node_modules/cesium/Build/Cesium/ThirdParty', to: 'ThirdParty' }, | ||
{ from: 'node_modules/cesium/Build/Cesium/Assets', to: 'Assets' }, | ||
{ from: 'node_modules/cesium/Build/Cesium/Widgets', to: 'Widgets' } | ||
], | ||
{ from: path.join(cesiumSource, cesiumWorkers), to: 'Workers' }, | ||
{ from: path.join(cesiumSource, 'Assets'), to: 'Assets' }, | ||
{ from: path.join(cesiumSource, 'Widgets'), to: 'Widgets' } | ||
srothst1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
}), | ||
new webpack.DefinePlugin({ | ||
// Define relative base path in cesium for loading assets | ||
CESIUM_BASE_URL: JSON.stringify('') | ||
}) | ||
], | ||
|
||
// development server options | ||
devServer: { | ||
contentBase: path.join(__dirname, "dist") | ||
} | ||
}]; | ||
mode: 'development', | ||
devtool: 'eval', | ||
}; |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change all URLs in this file from
AnalyticalGraphicsInc
->CesiumGS
, andcesiumjs.org
->cesium.com
, or use best judgement as needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. You may have noticed that the
README.MD
file in the branch was simply a relic from the last webpack tutorial that we released. It is mostly relevant to people who view our GitHub page, not users accessing our tutorial. I just added a commit that addresses this issue.