Live Platform
  • Introduction
  • Release Notes
    • Live 3
      • 3.59.0
      • 3.58.0
      • 3.57.0
      • 3.56.0
      • 3.55.0
      • 3.54.0
      • 3.53.0
      • 3.52.0
      • 3.51.0
      • 3.50.0
      • 3.49.0
      • 3.48.0
      • 3.47.0
      • 3.46.0
      • 3.45.0
      • 3.44.0
      • 3.43.0
      • 3.42.0
      • 3.41.0
      • 3.40.0
      • 3.39.0
      • 3.38.0
      • 3.37.0
      • 3.36.0
      • 3.35.0
      • 3.34.0
      • 3.33.0
      • 3.32.0
      • 3.31.0
      • 3.30.0
      • 3.29.0
      • 3.28.0
      • 3.27.0
      • 3.26.0
      • 3.25.0
      • 3.24.0
      • 3.23.0
      • 3.22.0
      • 3.21.0
      • 3.20.0
      • 3.19.0
      • 3.18.0
      • 3.17.0
      • 3.16.0
      • 3.15.0
      • 3.14.0
      • 3.13.0
      • 3.12.0
      • 3.11.0
      • 3.10.0
      • 3.9.0
      • 3.8.0
      • 3.7.0
      • 3.6.0
      • 3.5.0
      • 3.4.0
      • 3.3.0
      • 3.2.0
      • 3.1.0
      • 3.0.0
    • Live 2
  • Articles
    • Creating an aggregation
    • Creating a pipe
  • Theoretical Background
    • Fundamentals
    • Key Advantages
  • Platform Architecture
    • Introduction
    • Queries
    • Glossary
  • Featured plugins
    • Annotations
    • Groovy support
    • Messenger
    • Microsoft Teams
    • MongoDB
    • MongoDB Timeseries
    • MongoDB Kit
    • Purge plugin
    • SQL
    • TCP Input
    • TimescaleDB
  • Data visualization
    • Pipes widgets
      • Temporal
      • Cartesian
      • Multi-value snapshot
      • Single-value snapshot
      • Tables
      • Heatmap
      • JSX Widgets
      • Lollipop
      • Histogram
      • State Timeline
      • Boxplot
    • Pipes modifiers on Pipes charts
  • Alerts and notifications
    • Pipes modifiers on rules
  • Pipes Queries
    • Introduction
    • Dynamic filters
    • Meta parameters
    • Reducer
      • Uniform compress
      • PIP
    • Storage Hints
    • Execution Context
    • Event flow modifiers
  • Developers
    • Plugins
    • Packages
    • Backend API
      • Lookup Tables
      • Extensions
      • Settings
      • Storage Providers
      • Web Services
      • Web Setup
      • Entity Audit
    • Web application
      • Services
        • Point service
        • Menu service
      • Browser Compatibility
      • Runtime modules
        • Core Javascript modules
        • Library modules
        • Adding modules to runtime
      • Localization (i18n)
      • Date formatting
      • Dashboard and Widgets
        • Widget API
        • Custom widget editors
        • Live Event Types
        • Live Widget Configuration
        • Live Widget Packaging
        • Widget Request Interceptors
      • React Contexts
        • Dashboard
        • Dashboard widget
      • Registering Home Page options
    • Python application
    • Subscribing to Live Events
  • Administration
    • Configuration
      • Home Page Customization
      • live.properties
    • Infrastructure Monitoring
    • Storage Monitoring
    • Queries Monitoring
    • Logs Monitoring
    • Data Purging
  • Features
    • Access Permission
    • Datasources
    • Export Dashboard
    • Partial Indexes
    • WebApp Metrics
    • Entity Audit
Powered by GitBook
On this page
  • The directory structure
  • Exposing the entire "shared" directory
  • Import the shared index file from the app entry point
  • Example result
  • 1. Configure your webpack.config.js to treat these modules as external
  • 2. Configure your pom.xml to add explicitly show that dependency
  • 3. Import from plugin-example in any module

Was this helpful?

  1. Developers
  2. Web application
  3. Runtime modules

Adding modules to runtime

Any script can extend the runtime module system, Live offers a utility function to expose a directory of javascript modules.

PreviousLibrary modulesNextLocalization (i18n)

Last updated 3 years ago

Was this helpful?

The directory structure

It is advised to create a shared folder within your project, like so:

Exposing the entire "shared" directory

Inside the shared folder create index.ts file with the following content:

// exposeRequireContext depends on webpack's requireContext
import { exposeRequireContext } from 'live/expose'


// #see: https://webpack.js.org/guides/dependency-management/#requirecontext
const req = require.context(
    './', // require from current directory
    true, // recursive
    // it is important to ignore some folders and files
    /^(?!.*__tests__.*)^(?!.*\.stories\.*)^(?!.*Spec.js)^(?!.*worker.js)^(?!.*__mocks__.*\.js)((.*\.([t|j]sx?\.*))[^.]*$)/
)

// this call expose recursively all the modules on the current folder
// second argument is the prefix of the modules
exposeRequireContext(req, 'plugin-example/shared/')

Import the shared index file from the app entry point

app.tsx
import '../shared'
// ... rest of the app.tsx file

That's it! Your modules are ready to be required by another plugin's web application.

Example result

Before importing from plugin-example there are some configurations needed to be set up.

1. Configure your webpack.config.js to treat these modules as external

webpack.config.js
...
    externals: [
        function(context, request, callback) {
            // tells webpack that plugin-example is an external module
            if (request.startsWith('plugin-example/'))
                return callback(null, 'commonjs ' + request)

            callback()
        }
    ]
...

2. Configure your pom.xml to add explicitly show that dependency

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
    <configuration>
        <archive>
            <manifestEntries>
                <name>${project.name}</name>
                <version>${project.version}</version>
                <build>${buildID}</build>
                <author>Intelie</author>
                <entryPoint>net.intelie.example.plugin.pioneer.Main</entryPoint>
                <!-- explicit depdendency to plugin-example -->
                <requirePlugins>plugin-example@1.1.2,plugin-another-example@1.1.2</requirePlugins>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>
...

Now you're set up to import modules from plugin-example!

3. Import from plugin-example in any module

import util from 'plugin-example/shared/util'
Suggested directory structure