From 95e0eea86c18aaf8b5ab81f474fdb8a79cd3a2c4 Mon Sep 17 00:00:00 2001 From: Marcus Andersson Date: Mon, 15 Nov 2021 10:20:55 +0100 Subject: [PATCH] Docs: Adding details about how to enable dynamic imports in plugins (#41648) * added dynamic import to the readme. * Update packages/grafana-toolkit/README.md Co-authored-by: Levente Balogh * Update README.md Co-authored-by: Levente Balogh --- packages/grafana-toolkit/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/grafana-toolkit/README.md b/packages/grafana-toolkit/README.md index cd9938616ea..bbb06243b36 100644 --- a/packages/grafana-toolkit/README.md +++ b/packages/grafana-toolkit/README.md @@ -300,6 +300,24 @@ If your comments include ES2016 code, then SystemJS v0.20.19, which Grafana uses To fix this error, remove the ES2016 code from your comments. +### I would like to dynamically import modules in my plugin + +Create a webpack.config.js with this content (in the root of _your_ plugin) + +```ts +// webpack.config.js +const pluginJson = require('./src/plugin.json'); +module.exports.getWebpackConfig = (config, options) => ({ + ...config, + output: { + ...config.output, + publicPath: `public/plugins/${pluginJson.id}/`, + }, +}); +``` + +The plugin id is the id written in the plugin.json file. + ## Contribute to grafana-toolkit You can contribute to grafana-toolkit by helping develop it or by debugging it.