Import JS in plugin

Hello. We are developing custom Plugin. Is there a way to add our own JS file so it will run when we import our plugin in Graylog server?

Hey @BohdanSkarzhevskyi,

yes, there probably is. But it depends on what your JS file is supposed to do?

@dennis Thanks for quick response.
It’s supposed to manipulate DOM, the main goal is to show base64 strings in logs as images. We managed to do this locally using graylog2-web-interface hot-reload.
But when we build JAR file and move it in graylog server - we don’t have our JS file there. We tried manipulating webpack.config.js to include JS file in JAR build, but no success.

Can you show me what you tried to do in webpack.config.js? It should work by modifying the plugins’ webpack config.

We tried different options in webpack.config, here is the latest one:

const PluginWebpackConfig = require('graylog-web-plugin').PluginWebpackConfig;
const loadBuildConfig = require('graylog-web-plugin').loadBuildConfig;
const path = require('path');

module.exports = new PluginWebpackConfig('org.graylog.plugins.sample.SamplePlugin', loadBuildConfig(path.resolve(__dirname, './build.config')), {
    module: {
        rules: [
            { test: /\.ts$/, use: ['babel-loader', 'ts-loader'], exclude: /node_modules|\.node_cache/ },
	    { test: /\.jsx?$/ ,
	      exclude: /node_modules/,
	      use : [
		{
			loader: 'babel-loader',
			options
				presets: ['@babel/preset-env','@babel/preset-react']
        }}]},
        { test: /\.js$/ ,
                  exclude: /node_modules/,
                  use : [
                {
                    loader: 'babel-loader',
                    options
                        presets: ['@babel/preset-env','@babel/preset-react']
        }}]}
        ]
    },
    resolve: {
        extensions: ['.ts', '.jsx', '.js'],
    },
});

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.