Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolkit: Wrong publicPath used for plugin files #40671

Closed
ZuperZee opened this issue Oct 20, 2021 · 3 comments · Fixed by #41648
Closed

Toolkit: Wrong publicPath used for plugin files #40671

ZuperZee opened this issue Oct 20, 2021 · 3 comments · Fixed by #41648

Comments

@ZuperZee
Copy link
Contributor

What happened:

When using dynamic imports the code tries to retrieve the file from the base.
image

What you expected to happen:

The code should retrieve the code from the plugin path.

How to reproduce it (as minimally and precisely as possible):

Create a plugin.
Create a file to import

test.ts

export default "test"

import the file

panel.ts

...
      import('./test').then(({ default: test }) => {
        console.log(test);
      });
...

Anything else we need to know?:

Environment:

  • Grafana version: v8.2.0
  • Data source type & version:
  • OS Grafana is installed on:
  • User OS & Browser:
  • Grafana plugins:
  • Others:
@ZuperZee
Copy link
Contributor Author

should be

publicPath: `public/plugins/${getPluginId()}`,

There could be some problems if some plugins based the code that it loads code from the base.

@ZuperZee
Copy link
Contributor Author

ZuperZee commented Oct 20, 2021

A workaround is to create a webpack.config.js with this content (in the root of your plugin)

webpack.config.js

module.exports.getWebpackConfig = (config, options) => ({
  ...config,
  output: {
    ...config.output,
    publicPath: 'public/plugins/plugin-id/',
  },
});

The plugin id is the id written in the plugin.json file.

ZuperZee added a commit to gapitio/gapit-htmlgraphics-panel that referenced this issue Oct 20, 2021
Because of this issue grafana/grafana#40671,
the publicPath needs to be set to the plugin path.

Closes #48
@ying-jeanne ying-jeanne added this to Backlog in Plugins Platform (DEPRECATED) via automation Oct 22, 2021
@mckn mckn moved this from Backlog to Planned in Plugins Platform (DEPRECATED) Oct 26, 2021
@mckn mckn added the type/bug label Oct 26, 2021
@mckn
Copy link
Contributor

mckn commented Nov 12, 2021

You are correct! However we are a bit hesitant to introduce this into the grafana-toolkit since it might have a negative impact on older angular plugins that are using the "legacy imports".

I will add this to the documentation about how to dynamically import modules in your plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants