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.
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:
- Make sure you have the command line programs
git
, andnode
version 8 or greater - Clone the main frontend repository:
git clone https://github.com/oskariorg/oskari-frontend.git
- Clone the application repository (this one):
git clone https://github.com/oskariorg/sample-application.git
- Now we have directories
oskari-frontend
andsample-application
side by side
- Now we have directories
- 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.
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.
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.
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
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:
- Clone the contrib repository:
git clone https://github.com/oskariorg/oskari-frontend-contrib.git
- Go to
oskari-frontend-contrib
directory and runnpm install
. - Edit your application's
package.json
by adding"oskari-frontend-contrib": "file:../oskari-frontend-contrib"
to the dependencies section. - 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
.
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.
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).
Run npm start
for development server with auto reload for JS and hot reload for SCSS.
All Oskari-related issues should be reported here: https://github.com/oskariorg/oskari-docs/issues
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
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
})
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.