cesium/Documentation/Contributors/BuildGuide/README.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
9.5 KiB
Markdown
Raw Permalink Normal View History

2015-12-18 23:46:25 +08:00
# Build Guide
- [Quickstart](#quickstart)
- [Get the Code](#get-the-code)
- [Build the Code](#build-the-code)
- [Development Server](#development-server)
- [Build Output](#build-output)
- [Build Scripts](#build-scripts)
2015-12-18 23:46:25 +08:00
2022-01-27 10:53:01 +08:00
## Quickstart
1. [Clone the repository](#get-the-code)
2022-01-27 10:53:01 +08:00
2022-07-12 03:39:36 +08:00
2. Install the dependencies
2022-01-27 10:53:01 +08:00
2022-05-31 21:50:32 +08:00
```bash
npm install
2022-01-27 10:53:01 +08:00
```
2024-08-29 14:47:08 +08:00
3. Build the project
2022-01-27 10:53:01 +08:00
```bash
npm run build
```
2024-08-29 14:47:08 +08:00
4. Start the [server](#development-server)
2022-01-27 10:53:01 +08:00
2022-05-31 21:50:32 +08:00
```bash
2022-01-27 10:53:01 +08:00
npm start
```
5. Navigate to : [`http://localhost:8080/`](http://localhost:8080)
2022-01-27 10:53:01 +08:00
2015-12-18 23:46:25 +08:00
## Get the Code
- [Setup Git](https://help.github.com/articles/set-up-git/#platform-all) if it isn't already.
- New to git or need a refresher? Now's a good time to learn! [Easy tutorials here.](https://guides.github.com/)
2015-12-18 23:46:25 +08:00
- Make sure your SSH keys are configured ([linux](https://help.github.com/articles/generating-ssh-keys#platform-linux) | [mac](https://help.github.com/articles/generating-ssh-keys#platform-mac) | [windows](https://help.github.com/articles/generating-ssh-keys#platform-windows)).
- Double-check your settings for name and email: `git config --get-regexp user.*`.
- Recommended Git settings:
- `git config --global fetch.prune true` - when fetching remote changes, remove any remote branches that no longer exist on the remote.
- `git config blame.ignoreRevsFile .git-blame-ignore-revs` - uses the ignore file to skip certain noisy revisions (like formatting) when running git blame. Alternatively, for VSCode users, install the GitLens extension, which will automatically use the ignore file.
2021-07-17 06:54:25 +08:00
- Have [commit access](https://github.com/CesiumGS/cesium/blob/main/Documentation/Contributors/CommittersGuide/README.md) to CesiumJS?
2015-12-18 23:46:25 +08:00
- No
- Fork [cesium](https://github.com/CesiumGS/cesium).
2021-07-17 06:54:25 +08:00
- Use the [GitHub website](https://github.com/CesiumGS/cesium/branches/all) to delete all branches in your fork except `main`.
2015-12-19 00:15:14 +08:00
- Clone your fork, e.g., `git clone git@github.com:yourusername/cesium.git`.
- Make changes in a branch, e.g., `git checkout -b my-feature`.
2015-12-18 23:46:25 +08:00
- Yes
- Clone the cesium repo, e.g., `git clone git@github.com:CesiumGS/cesium.git`
2015-12-19 00:15:14 +08:00
- Make changes in a branch, e.g., `git checkout -b my-feature`.
2015-12-18 23:46:25 +08:00
## Build the Code
Prerequisites:
2020-04-17 08:31:36 +08:00
- Install [Node.js](http://nodejs.org/) on your system. Building Cesium requires Node 20.x or newer.
2015-12-18 23:46:25 +08:00
2017-01-25 02:24:39 +08:00
Cesium uses [npm modules](https://docs.npmjs.com/getting-started/what-is-npm) for development, so after syncing, you need to run `npm install` from the Cesium root directory:
2015-12-18 23:46:25 +08:00
2022-05-31 21:50:32 +08:00
```bash
2015-12-18 23:46:25 +08:00
npm install
```
Cesium ships with a simple HTTP server for testing. Once all modules have been installed, run `npm run build` to build the project:
```bash
npm run build
```
2024-08-29 14:47:08 +08:00
Then, run the development server:
2015-12-18 23:46:25 +08:00
2022-05-31 21:50:32 +08:00
```bash
2015-12-18 23:46:25 +08:00
npm start
```
2017-01-26 22:15:03 +08:00
Then browse to [http://localhost:8080/](http://localhost:8080/). The landing page includes apps and tools commonly used during development, including:
2015-12-18 23:46:25 +08:00
2021-07-02 02:32:03 +08:00
- **Hello World** : an example for how to create a 3D globe. [Tutorial here](https://cesium.com/learn/cesiumjs-learn/cesiumjs-quickstart/)
2025-10-28 02:14:10 +08:00
- **Sandcastle** : an app for viewing and creating [code examples](https://sandcastle.cesium.com), complete with a live preview
2021-07-17 06:54:25 +08:00
- **Test Suites** : tests using [Jasmine](https://jasmine.github.io/). [Testing guide here.](https://github.com/CesiumGS/cesium/blob/main/Documentation/Contributors/TestingGuide/README.md#testing-guide)
- **Documentation** : reference documentation built from source. [Documentation guide here.](https://github.com/CesiumGS/cesium/blob/main/Documentation/Contributors/DocumentationGuide/README.md#documentation-guide)
2022-05-26 04:21:45 +08:00
### Development Server
2015-12-18 23:46:25 +08:00
2016-03-30 21:23:09 +08:00
By default, the server only allows connections from your local machine. To allow connections from other machines, pass
2015-12-18 23:46:25 +08:00
the `--public` option to npm. Note the extra `--` is intentional and required by npm.
2022-05-31 21:50:32 +08:00
```bash
2015-12-18 23:46:25 +08:00
npm start -- --public
```
2022-05-26 04:21:45 +08:00
The development server has a few other options as well, which you can see by passing the `--help` parameter:
2015-12-18 23:46:25 +08:00
2022-05-31 21:50:32 +08:00
```bash
2015-12-18 23:46:25 +08:00
npm start -- --help
```
2022-05-26 04:21:45 +08:00
### Build Output
2022-06-23 03:33:04 +08:00
Cesium offers a few different distributions. When developing, make sure to pick the one that fits your app's architecture.
2022-05-26 04:21:45 +08:00
2023-09-09 03:59:52 +08:00
- [IIFE (immediately-invoked function expression)](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) - A pre-processed bundle, optimized for the browser, and with web worker code inlined. It defines a `Cesium` global variable upon loading `Build/Cesium/Cesium.js`. This is what is available via the CDN. While much of our documentation uses IIFE-style globals for ease-of-use, we do not recommend this approach for production apps.
2022-06-23 03:33:04 +08:00
- [ESM (ECMAScript modules)](https://nodejs.org/api/esm.html) - Standard for packaging JS code which is supported by most browsers and NodeJS. Modules use `import` and `export` statements. Unprocessed, individual modules are available in the `Source` directory, accessible by importing `Source/Cesium.js`; A single pre-processed bundle by importing `Build/Cesium/index.js`.
2022-05-26 04:21:45 +08:00
- [CJS (CommonJS)](https://nodejs.org/api/modules.html) - A pre-processed, bundled module packaged for running in NodeJS accessible by requiring `index.cjs`.
2022-06-30 21:08:11 +08:00
In much of our documentation, we use IIFE as it can be easily loaded with a CDN and defines a global _Cesium_ variable with all modules attached.
2022-06-23 03:33:04 +08:00
2022-07-13 01:13:46 +08:00
For a production app, we recommend using the `Source` modules directly which will allow your build tool of choice to reduce the final release's size using tree shaking.
2022-06-23 03:33:04 +08:00
2022-05-26 04:21:45 +08:00
Read the complete list of build scripts and options below for more details.
2015-12-18 23:46:25 +08:00
While you can use the editor of your choice to develop Cesium, certain files, such as `glsl` and new tests, require that
2016-10-21 04:09:40 +08:00
the `build` task be executed in order for the changes to take effect. You can use the `build-watch` script to have this
2015-12-18 23:46:25 +08:00
happen automatically.
## Build Scripts
Cesium uses [gulp](http://gulpjs.com/) for build tasks, but they are all abstracted away by [npm run scripts](https://docs.npmjs.com/cli/run-script).
Specify the target(s) at the command line:
2022-05-31 21:50:32 +08:00
```bash
2015-12-18 23:46:25 +08:00
npm run [target-name]
```
Here's the full set of scripts and what they do.
2017-01-26 22:15:03 +08:00
- **Build scripts** -- build and package the source code and documentation
2022-06-23 03:33:04 +08:00
- `build` - A fast, developer-oriented build that bundles the source modules to produce all-in-one files in the `Build/CesiumUnminified` directory that exposes the entire Cesium API attached to a single global `Cesium` object. Run this when a GLSL shader is changed since the .glsl file is converted to a .js file with a string for the GLSL source.
2022-05-26 04:21:45 +08:00
- `--minify` - [Minifies](<http://en.wikipedia.org/wiki/Minification_(programming)>) the output for optimized loading. Specifying this option will output to `Build/Cesium`.
- `--removePragmas` - Optimizes the output by removing debugging code that validates function input and throws `DeveloperError`s. The removed sections are marked with `//>>includeStart('debug', pragmas.debug);` blocks in the code.
- `--node` - Bundles an `index.cjs` module targeted for use in NodeJS
- `build-watch` - A never-ending task that watches your file system for changes to Cesium and builds the source code as needed. All `build` options are also available for this task.
- `build-apps` - Builds the example applications (such as Cesium Viewer) to produce self-contained, minified, deployable versions in the `Build` directory.
- `build-docs` - Generates HTML documentation in `Build/Documentation` using [JSDoc 3](https://github.com/jsdoc3/jsdoc). See the [Documentation Guide](../DocumentationGuide/README.md) for more details.
2022-05-26 04:21:45 +08:00
- `build-ts` - Generates a TypeScript definitions file for the Cesium library
- `build-third-party` - Generates `ThirdParty.json`, a file which lists the latest licensing information of installed third party modules
2022-04-29 04:55:41 +08:00
- `release` - A full release build that creates a shippable product, including generating documentation.
- `make-zip` - Builds a zip file containing all release files. This includes the source ESM modules, bundled ESM and IIFE format `Cesium.js`, plus the bundled minified versions of ESM and IIFE, the generated documentation, the test suite, and the example applications (in both built and source form).
2017-01-26 22:15:03 +08:00
- **Utility scripts** -- code coverage, static code analysis, and other utilities
2022-05-26 04:21:45 +08:00
- `clean` - Removes all generated build artifacts
- `cloc` - Runs [CLOC](https://github.com/AlDanial/cloc) to count the lines of code on the Source and Specs directories. This requires [Perl](http://www.perl.org/) to execute.
2022-05-26 04:21:45 +08:00
- `coverage` - Runs coverage and opens the default browser with the results
- `eslint` - Runs [ESLint](http://eslint.org/), a static code analysis tool, on the entire source tree
- `prettier` - Formats the code base using [Prettier](https://prettier.io/)
- `prettier-check` - Verifies prettier formatting, but does not write the output
2017-01-26 22:15:03 +08:00
- **Testing scripts** -- build and run the unit tests
- `test` - Runs all tests with [Karma](http://karma-runner.github.io/0.13/index.html) using the default browser specified in the Karma config file.
2022-05-26 04:21:45 +08:00
- `test-all` - Runs all tests with Karma using all browsers installed on the current system
- `test-non-webgl` - Runs only non-WebGL tests
- `test-webgl` - Runs only WebGL tests
- `test-webgl-stub` - Runs all tests using the WebGL stub, which WebGL calls a noop and ignores related test expectations
- `test-webgl-validation` - Runs all tests with Karma and enables low-level WebGL validation
- `test-release` - Runs all tests on the minified release version of built Cesium
- **Deployment scripts**
- `deploy-status` - Sets the deployment statuses in GitHub, for use in CI
- `deploy-set-version` - Sets the version of `package.json`, for use in CI