Coder Social home page Coder Social logo

craco-cesiumext's Introduction

craco-cesiumext

Let's use 🌍CesiumExt with create-react-app today!

This is a plugin for @craco/craco.

Very very easy usage

1. Create a React project

npm install -g create-react-app
# or
yarn global add create-react-app

create-react-app example
cd example

2. Install modules

In your create-react-app project, install modules:

npm install --save @craco/craco @mapuiexts/craco-cesiumext @mapuiexts/react-cesiumext cesium
# or
yarn add @craco/craco @mapuiexts/craco-cesiumext @mapuiexts/react-cesiumext cesium

3. Rewrite npm scripts

Rewrite npm scripts in package.json as following:

{
  // ...
  "scripts": {
    "start": "craco start", // react-scripts -> craco
    "build": "craco build", // react-scripts -> craco
    "test": "craco test",   // react-scripts -> craco
    "eject": "react-scripts eject"
  },
  // ...
}

4. Create craco config file

Create craco.config.js in the project root:

module.exports = {
  plugins: [
    {
      plugin: require("@mapuiexts/craco-cesiumext")()
    }
  ]
};

5. Congratulations! πŸŽ‰

Set up is complete! Enjoy your CesiumExt life.

You can import Cesium as following:

import { Viewer, Entity, Color } from "cesium";

πŸ”₯Pro Tip: Enabling HMR

  • πŸ’‘ Example project is here.
  1. yarn add craco-plugin-react-hot-reload react-hot-loader @hot-loader/react-dom

⚠️ @hot-loader/react-dom's version should be the same as react's.

  1. Add an alias of webpack and craco-plugin-react-hot-reload plugin to craco.config.js:
module.exports = {
  webpack: {
    alias: {
      "react-dom": "@hot-loader/react-dom"
    }
  },
  plugins: [
    { plugin: require("craco-plugin-react-hot-reload") },
    { plugin: require("@mapuiexts/craco-cesiumext")() }
  ]
};
  1. Wrap root component with hot function in src/App.js
export default App;

to

import { hot } from "react-hot-loader/root";

// ~~~~~~~~~~~~~~~~~~~~~~~~~

export default hot(App);

Done!

Please refer to react-hot-loader to refer to the details.

Options

If the option is omiited, the default options is used:

CracoCesiumPlugin({
  loadPartially: false,
  loadCSSinHTML: true,
  cesiumPath: "cesium"
});

loadPartially

If false, whole Cesium will be loaded in HTML and window.Cesium is used in import { ... } from "cesium";. This is the easiest way.

Otherwise, Cesium will be load partially and bundled in the JS. You have to install strip-pragma-loader to build Cesium for production: npm i -S strip-pragma-loader.

For more details, refer to Cesium official tutorial.

loadCSSinHTML

If true, Widgets/widgets.css in Cesium is loaded in HTML.

Otherwise, you have to load the CSS once manually as following.

If loadPartially is true:

import "cesium/Widgets/widgets.css";

Otherwise:

import "cesium/Build/CesiumUnminified/Widgets/widgets.css";

cesiumPath

Directory path destination to copy Cesium files.

craco-cesiumext's People

Contributors

paulossaragao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.