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

Revised our public CesiumJS & webpack guide #28

Merged
merged 99 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
5b74985
revised CesiumJS & webpack guide
srothst1 Aug 17, 2021
cf65181
updated webpack.config.js
srothst1 Aug 18, 2021
d44239f
minor updates
srothst1 Aug 23, 2021
cd610d2
updated webpack-dev-server
srothst1 Aug 25, 2021
b3243bf
updated index.js
srothst1 Aug 25, 2021
7111d30
updating Cesium alias
srothst1 Aug 26, 2021
e7b17fa
removed tag
srothst1 Aug 26, 2021
c0eb8b6
removed whitespace
srothst1 Aug 26, 2021
a7849c3
updated dependencies
srothst1 Aug 26, 2021
477fce6
updated .travis.yml
srothst1 Aug 26, 2021
60d0683
updated imports
srothst1 Aug 26, 2021
b5494b2
updated index.js and index.html
srothst1 Aug 30, 2021
dde2b44
1.0.0-canary.0
srothst1 Aug 30, 2021
67025e8
trying to resolve Travis CI issues
srothst1 Aug 30, 2021
e723825
trying to resolve Travis CI issues part 2
srothst1 Aug 30, 2021
a8c1867
trying to resolve Travis CI issues part 3
srothst1 Aug 30, 2021
dcfca51
trying to resolve Travis CI issues part 4
srothst1 Aug 30, 2021
75887f3
trying to resolve Travis CI issues part 5
srothst1 Aug 30, 2021
a180410
trying to resolve Travis CI issues part 6
srothst1 Aug 30, 2021
4deb9d8
trying to resolve Travis CI issues part 7
srothst1 Aug 30, 2021
b4d8d41
trying to resolve Travis CI issues part 8
srothst1 Aug 30, 2021
34dbfc2
trying to resolve Travis CI issues part 9
srothst1 Aug 30, 2021
5d7deb9
trying to resolve Travis CI issues part 10
srothst1 Aug 30, 2021
d702e46
removed the release configuration
srothst1 Aug 30, 2021
3fa578b
removed release.config
srothst1 Aug 30, 2021
f93b2e1
adding a whitespace to src/index.js
srothst1 Aug 30, 2021
f778103
updating tutorial
srothst1 Aug 31, 2021
529b72b
updating tutorial pt 2
srothst1 Sep 1, 2021
a15c18e
updated heading size
srothst1 Sep 1, 2021
ce4300f
Updated step 6 of TUTORIAL.md
srothst1 Sep 3, 2021
8e1b362
CopywebpackPlugin -> CopyWebpackPlugin
srothst1 Sep 3, 2021
e1087b1
updated heading size
srothst1 Sep 3, 2021
02fd982
removed devServer
srothst1 Sep 7, 2021
65a5b5b
Update TUTORIAL.md
srothst1 Sep 15, 2021
0f1a9cc
Update TUTORIAL.md
srothst1 Sep 15, 2021
bba8ff5
Update TUTORIAL.md
srothst1 Sep 15, 2021
abafe58
Update TUTORIAL.md
srothst1 Sep 15, 2021
b136ad7
Update TUTORIAL.md
srothst1 Sep 15, 2021
5ca60be
Update TUTORIAL.md
srothst1 Sep 15, 2021
a8669a5
Update TUTORIAL.md
srothst1 Sep 15, 2021
da88a4d
Update TUTORIAL.md
srothst1 Sep 15, 2021
72fe12d
Update TUTORIAL.md
srothst1 Sep 15, 2021
c0b0dfc
Update TUTORIAL.md
srothst1 Sep 15, 2021
1a216a4
Update TUTORIAL.md
srothst1 Sep 15, 2021
78231bc
Update TUTORIAL.md
srothst1 Sep 15, 2021
4877406
Update TUTORIAL.md
srothst1 Sep 15, 2021
af71f1a
Update TUTORIAL.md
srothst1 Sep 15, 2021
076ad35
Update TUTORIAL.md
srothst1 Sep 15, 2021
e8db53a
Update TUTORIAL.md
srothst1 Sep 15, 2021
21673a7
Update TUTORIAL.md
srothst1 Sep 15, 2021
6207790
Update TUTORIAL.md
srothst1 Sep 15, 2021
09f12e0
Update TUTORIAL.md
srothst1 Sep 15, 2021
8058aea
Update TUTORIAL.md
srothst1 Sep 15, 2021
308697a
Update TUTORIAL.md
srothst1 Sep 15, 2021
073a8b9
Update TUTORIAL.md
srothst1 Sep 15, 2021
833b653
Update TUTORIAL.md
srothst1 Sep 15, 2021
277cb85
Update TUTORIAL.md
srothst1 Sep 15, 2021
7f53ee2
Update TUTORIAL.md
srothst1 Sep 15, 2021
02dfd9f
updated webpack links
srothst1 Sep 16, 2021
b489751
updated TUTORIAL.md with more details
srothst1 Sep 16, 2021
252fc4e
updated CopyWebpackPlugin
srothst1 Sep 16, 2021
0a5d5dc
removed extra line
srothst1 Sep 16, 2021
da0c686
updated author/keyword/licesne information
srothst1 Sep 16, 2021
e3dd1a9
updated package.json
srothst1 Sep 16, 2021
22869b3
removed the contributors section
srothst1 Sep 16, 2021
eabfe69
Update TUTORIAL.md
srothst1 Oct 11, 2021
9426429
updated the dependencies in package.json
srothst1 Oct 18, 2021
557f990
updated the dependencies in package.json
srothst1 Oct 18, 2021
d764308
updated the webpack resolve statement and the js imports
srothst1 Oct 18, 2021
02379b4
added back css
srothst1 Oct 18, 2021
ed102e7
added Gabby's most recent suggestions to the tutorial
srothst1 Oct 18, 2021
6f8ca94
updated main files
srothst1 Oct 20, 2021
21804ab
updated the devDependencies
srothst1 Oct 20, 2021
d8cc595
removed white space in css file
srothst1 Oct 20, 2021
c71cc23
updated npm packages
srothst1 Oct 20, 2021
2d70cdc
updated URLs in README file
srothst1 Oct 21, 2021
0cce7db
changed wording from we -> you
srothst1 Oct 21, 2021
523f412
updated npm link phrasing
srothst1 Oct 21, 2021
27abc22
added a You'll learn how to section
srothst1 Oct 21, 2021
0d77de6
removed line about code text editor
srothst1 Oct 21, 2021
73fa09d
using Tile case for all headers
srothst1 Oct 21, 2021
1300b73
moved boilerplate phrase above code
srothst1 Oct 21, 2021
6e97a9d
Remove empty line between list. Also below.
srothst1 Oct 21, 2021
d929d66
Add empty line after heading
srothst1 Oct 21, 2021
a117a63
hyperlinked sections
srothst1 Oct 21, 2021
6d8aa9c
made webpack upper case
srothst1 Oct 21, 2021
d5a4474
changed output wording
srothst1 Oct 21, 2021
1f31926
changed wording around app.js bundle
srothst1 Oct 21, 2021
6f12f01
verify not ensure
srothst1 Oct 21, 2021
e605e06
updated filename
srothst1 Oct 21, 2021
5f40257
updated working around
srothst1 Oct 21, 2021
7cb9819
changed wording of Incorporate CesiumJS
srothst1 Oct 21, 2021
e972bac
more descriptive filenames
srothst1 Oct 21, 2021
eb02aac
updated wording around demo showcase
srothst1 Oct 21, 2021
ae53686
updated md syntax
srothst1 Oct 21, 2021
7de3fbd
updated token wording
srothst1 Oct 22, 2021
1f31648
install cesiumjs is level three header
srothst1 Oct 22, 2021
f0dea0c
added a commit that fixed the markdown syntax and formatting
srothst1 Oct 22, 2021
83bab72
updated the sandcastle demo that we are showcasing
srothst1 Oct 22, 2021
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ node_js:
- '10'
- '12'
script:
- npm run build
- npm run release
- npm run build
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,3 @@ Pull requests are appreciated. Please use the same [Contributor License Agreemen
---

Developed by the Cesium team.

Copy link
Member

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, and cesiumjs.org -> cesium.com, or use best judgement as needed.

Copy link
Contributor Author

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.

<a href="https://cesium.com/"><img alt="Cesium" src="doc/cesium.png" /></a>
386 changes: 386 additions & 0 deletions TUTORIAL.md

Large diffs are not rendered by default.

50 changes: 21 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
{
"name": "cesium-webpack-example",
"name": "cesiumjs-webpack-tutorial",
"version": "1.0.0",
"description": "The minimal recomended setup for an app using Cesium with Webpack.",
"description": "Getting started with CesiumJS and Webpack.",
"main": "index.js",
"keywords": [
"cesium",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nitpick-y, but cesium would still be a good keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

"webpack",
"example"
],
"author": {
"name": "Cesium GS, Inc.",
"url": "https://cesium.com"
},
"homepage": "https://cesiumjs.org",
"license": "Apache-2.0",
"dependencies": {
"cesium": "^1.63.1"
"scripts": {
"build": "node_modules/.bin/webpack --config webpack.config.js",
"start": "node_modules/.bin/webpack serve --config webpack.config.js --open"
},
"author": "Sam Rothstein",
srothst1 marked this conversation as resolved.
Show resolved Hide resolved
"license": "ISC",
"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": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there not only be one dependency

"cesium": "^1.84.0",

and all others are being devDependencies?

"cesiumjs": "^1.10.0",
Copy link
Contributor

@ggetz ggetz Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cesiumjs shouldn't be here at all - Use cesium which is already included above in "devDependencies".

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
Regardless, I removed the "cesiumjs": "^1.10.0" dependency.

"es6": "^0.0.7",
"release": "^6.3.0",
"webpack": "^5.51.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all of these are devDependencies in this case, as suggested above.

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggetz good point 😄 I just ran the command depcheck to find the unused npm packages in package.json as suggested here. It initially looked like the following dependencies were not necessary.

Unused devDependencies
* sass-loader
* strip-pragma-loader
* webpack-cli
* webpack-dev-server
* es6
* querystring-es3
* release

However, when running npm run build and npm run start, I realized that webpack-dev-server and webpack-cli are actually necessary. I just pushed a commit that addresses this 👍

}
}
Binary file added screenshots/fw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/hw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/ssf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/ssf2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 0 additions & 7 deletions src/css/main.css

This file was deleted.

18 changes: 8 additions & 10 deletions src/index.html
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>
31 changes: 18 additions & 13 deletions src/index.js
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';
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then the comment This is the default access token from your ion account is invalid. Its not a token from the users account.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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),
}
});
52 changes: 24 additions & 28 deletions webpack.config.js
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)
Copy link
Contributor

@ggetz ggetz Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've defined the cesium alias here, but I don't see it used in src/index.js.

It's pretty atypical to define relative paths to dependencies in node_modules from source code like what's currently happening in index.js. Instead, you usually rely on the package name itself which webpack resolves from node_modules just like node resolves.

At first, I would have suggested omitting the resolve property altogether, which would make the first line in index.js

import { Ion, Viewer, createWorldTerrain, createOsmBuildings, Cartesian3, Math } from "cesium";

However, there's an issue when importing Widgets/widgets.css. In regards to css files with cesium and webpack, there's actually an issue in the CesiumJS repo advising the best configuration. Basically, we don't explicitly export anything other than JS files as part of the cesium npm package, which means webpack does not allow us to resolve CSS files like js modules.

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 webpack.config.js, resolve becomes

    resolve: {
        alias: {
            cesium: path.resolve(__dirname, cesiumSource)
        },
        mainFiles: ['index', 'Cesium']
    },

and the first few lines of index.js become

import { Ion, Viewer, createWorldTerrain, createOsmBuildings, Cartesian3, Math } from "cesium";
import "cesium/Widgets/widgets.css";

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, instead of a resolve.alias entry in Webpack, it would be ideal if you could set up the package.json so that import { Viewer } from "cesium" just works for everybody -- webpack, rollup, or node. It's been a minute since I reviewed the relevant fields but I think this should be practical, at least as long as you're only supporting webpack 5+.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 package.json file is updated.

}
},
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: [
Expand All @@ -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',
};
73 changes: 0 additions & 73 deletions webpack.release.config.js

This file was deleted.