Giter Club home page Giter Club logo

sample-application's Introduction

alt text Sample application

This is an example that can be used as a template for building Oskari application frontend.

Click the "Use this template" button on the repository to create a copy of the files under your username and start customizing it.

This application can be seen in http://dev.oskari.org. For backend see https://github.com/oskariorg/sample-server-extension.

Setup

This repository and the main oskari-frontend repository should be located side by side on your filesystem. Here are the steps to setup the build environment:

  1. Make sure you have the command line programs git, and node version 8 or greater
  2. Clone the main frontend repository: git clone https://github.com/oskariorg/oskari-frontend.git
  3. Clone the application repository (this one): git clone https://github.com/oskariorg/sample-application.git
    • Now we have directories oskari-frontend and sample-application side by side
  4. Run npm install in both above repo directories

Running npm install in this repo will create symlinks to the oskari-frontend directory under node_modules.

In this model, it's left to the developer to checkout the correct branches/versions of the above repos.

Creating your own Oskari application

After you have done the basic setup (above), the application can be built directly from this repo with eg. npm run build -- --env.appdef=1.0.0:applications. The output will be under dist/.

See the main oskari-frontend repo for detailed instructions about the build parameters.

App composition

An Oskari frontend application consists of bundles that are defined in the main.js for each app (an example can be found here). Only bundles referenced here can be instantiated at runtime.

The applications use oskari-frontend framework's Webpack to create builds. The framework introduces loaders that can be used for importing Oskari bundles.

  • oskari-loader

    Bundles will be included to the main app js bundle.

  • oskari-lazy-loader

    Bundles are loaded dynamically at runtime. These bundles won't be included in the main app js bundle.

Bundles that are used only in a limited part of the app (for example admin tools) can be configured to load dynamically by using the oskari-lazy-loader.

Using lazy loader will decrease the size of the main app JS bundle and speed up the page loading.

Managing dependencies

With the symlinks in place import-statements and other path references to oskari-frontend will resolve to the appropriate directories. This means you can reference bundles in oskari-frontend repo with eg. import 'oskari-loader!oskari-frontend/packages/statistics/statsgrid/bundle.js' in main.js.

If you wan't to build a custom bundle using oskari-frontend components, you can reference those by using oskari-frontend in bundle.js.

scripts: [
    {
        type: "text/javascript",
        src: "oskari-frontend/bundles/mapping/mapmodule/AbstractMapModule.js"
    }
]

Oskari frontend contrib

oskari-frontend-contrib repository contains unofficial bundles and applications for Oskari created by the Oskari community. If you want to use the contrib bundles, you should clone the contrib repo next to your application repository and take following steps:

  1. Clone the contrib repository: git clone https://github.com/oskariorg/oskari-frontend-contrib.git
  2. Go to oskari-frontend-contrib directory and run npm install.
  3. Edit your application's package.json by adding "oskari-frontend-contrib": "file:../oskari-frontend-contrib" to the dependencies section.
  4. Run npm install in your application directory.

You can then reference contrib components using oskari-frontend-contrib the same way you can use oskari-frontend.

Libraries

Before adding a library dependency (either under libraries/ or via NPM), you should check if the library is already included in oskari-frontend repo. If it is, you can reference it in your bundle.js with eg. oskari-frontend/libraries/geostats/1.5.0/lib/geostats.min.js. NPM package dependencies defined in oskari-frontend repo can be imported directly in code found in this repo eg. Open Layers import olMap from 'ol/Map';. Note: this is not how node module resolution usually works; it's a special feature of the Oskari build system aimed to avoid library code duplication & version conflicts. To see which packages can be used in this way, see dependencies in oskari-frontend package.json.

If the library isn't included in oskari-frontend repo, you can add it into this repo, either as dependency in package.json (preferred) or under libraries/. Dependencies under libraries/ require a reference in bundle.js, NPM dependencies do not; just import in your code.

Customized application icons

It's possible to override any icon in oskari-frontend/resources/icons with app-specific icons. To add icons for your application or to override icons: include a folder named icons under the application folder. To replace an icon provide a png-file with the same name as in oskari-frontend/resources/icons. For maximum compatibility the pixel size for overridden icon should match the original. Any png-files in the app-specific icons folder will be included in the sprite that is generated so this can be used to add icons for app-specific bundles.

After running the production build it's possible to create a customized set of icons for the application by running a command npm run sprite -- [version]:[application path] like

npm run sprite -- 1.0.0:applications/geoportal

Note! Requires (GraphicsMagick)[http://www.graphicsmagick.org/] to be installed on the server and the "gm" command to be usable on the cmd/bash.
Note! You must first run a production build for the application to create the corresponding dist-folder. With the example command the sprite will be generated under the dist\1.0.0\geoportal folder as icons.png and icons.css.
Note! To use the customized icons set your HTML (JSP) on the oskari-server need to link the icons.css under the application folder (default JSP links it from under oskari-frontend/resources/icons.css).

Development server

Run npm start for development server with auto reload for JS and hot reload for SCSS.

Reporting issues

All Oskari-related issues should be reported here: https://github.com/oskariorg/oskari-docs/issues

FAQ

"Out of memory" error when running Webpack

If you get an error when running the build like "FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory" or "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory" you need to configure some more memory for the node-process.

In linux you can use:

export NODE_OPTIONS=--max_old_space_size=4096
npm run build -- --env.appdef=1.0.0:applications

Or in Windows:

set NODE_OPTIONS=--max_old_space_size=4096 && npm run build -- --env.appdef=1.0.0:applications

Production build "freezes"

CPU usage of the computer shows nothing is happening, but the bash/cmd is still executing the build command. Try setting "parallel" to false on UglifyJsPlugin configuration in webpack.config.js:

new UglifyJsPlugin({
    sourceMap: true,
    parallel: false
})

Build fails on an error

npm ERR! path [...]
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '[...]' -> '[...]'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

This is most likely due to package-lock.json being present in your environment. Package locking mechanism doesn't work gracefully with symlinked node_modules (oskari-frontend / oskari-frontend-contrib). Remove package-lock.json for now.

sample-application's People

Contributors

zakarfin avatar jheijari avatar masapu avatar krotti avatar kessu avatar thekarppinen avatar kuosman avatar data-ux avatar usman45 avatar hvisuri avatar nxholm avatar sampov2 avatar dostumut avatar sito-strzyzewski avatar jruutiai avatar mikaelsc5 avatar mikkomustikkamaa avatar tmurtola avatar nls-jajuko 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.