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

update webpack dependencies and config #52

Merged
merged 2 commits into from
Jan 5, 2024
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ var c = Color.fromRandom();
import "cesium/Build/Cesium/Widgets/widgets.css";
```

## Cesium sub-packages

CesiumJS requires a few static files to be hosted on your server, like web workers and SVG icons. This example is set up to copy these directories already if you install the whole `cesium` package. However if you only install `@cesium/engine` then you should change the paths in `webpack.config.js` to the ones below:

```js
new CopyWebpackPlugin({
patterns: [
{ from: 'node_modules/@cesium/engine/Build/Workers', to: `${cesiumBaseUrl}/Workers` },
{ from: 'node_modules/@cesium/engine/Build/ThirdParty', to: `${cesiumBaseUrl}/ThirdParty` },
{ from: 'node_modules/@cesium/engine/Source/Assets', to: `${cesiumBaseUrl}/Assets` },
],
}),
```

## Removing pragmas

To remove pragmas such as a traditional Cesium release build, use the [`strip-pragma-loader`](https://www.npmjs.com/package/strip-pragma-loader).
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.config.js",
"start": "webpack serve --config webpack.config.js --open",
"start": "webpack serve --config webpack.config.js",
"start:built": "npx http-server -a localhost -p 8080 dist/",
"eslint": "eslint \"./**/*.js\" \"./**/*.html\" --cache --quiet",
"prettier": "prettier --write --no-config \"**/*\"",
"prettier-check": "prettier --check --no-config \"**/*\""
},
"devDependencies": {
"cesium": "^1.113.0",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.2.0",
"copy-webpack-plugin": "^9.1.0",
"css-loader": "^6.8.1",
"eslint": "^8.56.0",
"eslint-config-cesium": "^10.0.2",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-html": "^7.1.0",
"html-webpack-plugin": "^5.3.2",
"html-webpack-plugin": "^5.6.0",
"husky": "^8.0.3",
"prettier": "^3.1.1",
"style-loader": "^3.2.1",
"url-loader": "^4.1.1",
"webpack": "^5.51.1",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.3.1"
"style-loader": "^3.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.15.1"
},
"lint-staged": {
"*.{js,cjs,html}": [
Expand Down
31 changes: 23 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";

// The path to the CesiumJS source code
jjspace marked this conversation as resolved.
Show resolved Hide resolved
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 cesiumSource = "node_modules/cesium/Build/Cesium";
// this is the base url for static files that CesiumJS needs to load
// Not required but if it's set remember to update CESIUM_BASE_URL as shown below
const cesiumBaseUrl = "cesiumStatic";

module.exports = {
context: __dirname,
entry: {
Expand All @@ -30,7 +33,7 @@ module.exports = {
},
{
test: /\.(png|gif|jpg|jpeg|svg|xml|json)$/,
use: ["url-loader"],
type: "asset/inline",
},
],
},
Expand All @@ -41,15 +44,27 @@ module.exports = {
// Copy Cesium Assets, Widgets, and Workers to a static directory
new CopyWebpackPlugin({
patterns: [
{ from: path.join(cesiumSource, cesiumWorkers), to: "Workers" },
{ from: path.join(cesiumSource, "Assets"), to: "Assets" },
{ from: path.join(cesiumSource, "Widgets"), to: "Widgets" },
{ from: path.join(cesiumSource, "ThirdParty"), to: "ThirdParty" },
{
from: path.join(cesiumSource, "Workers"),
to: `${cesiumBaseUrl}/Workers`,
},
{
from: path.join(cesiumSource, "ThirdParty"),
to: `${cesiumBaseUrl}/ThirdParty`,
},
{
from: path.join(cesiumSource, "Assets"),
to: `${cesiumBaseUrl}/Assets`,
},
{
from: path.join(cesiumSource, "Widgets"),
to: `${cesiumBaseUrl}/Widgets`,
},
],
}),
new webpack.DefinePlugin({
// Define relative base path in cesium for loading assets
CESIUM_BASE_URL: JSON.stringify(""),
CESIUM_BASE_URL: JSON.stringify(cesiumBaseUrl),
}),
],
mode: "development",
Expand Down