Add custom files in Plugin

Answered

I am developing a plugin that will (hopefully) give the user rich autocompletion for Tailwindcss. For that to work I need to execute some JavaScript to generate the necessary data (classnames etc.) on the fly. Right now I'm struggling to bundle the necessary javascript files with my plugin. 

I tried to figure out how the PrettierJS plugin (https://github.com/JetBrains/intellij-plugins/tree/master/prettierJS/) does that, but with no luck so far. 

Thank you

0
4 comments

Jens,

For bundling additional files within your plugin, you should put them into the /src/main/resources directory and access them, i.e., using

InputStream is = YourClass.class.getResourceAsStream("/file.txt");
0

Thanks Jakub,

I already tried that but had problems (as in couldn't find a way to) to execute the bundled javascript file with nodejs. Another idea I had was to extract the files from the Jar, but that feels a bit clumsy. Would be nice to have it the same way as the aforementioned prettierJS plugin does it (like the prettierLanguageService folder):

% tree -L 2 prettierJS ~/Library/Application Support/JetBrains/IntelliJIdea2020.2/plugins/prettierJS
prettierJS
├── lib
│   ├── intellij.prettierJS.jar
│   └── resources_en.jar
└── prettierLanguageService
├── convert-prettier-config.js
├── prettier-plugin-provider.js
└── prettier-plugin.js
0

That's correct - you have to move these resources to the specific place to make them available for the external tools - it's plugin's directory in this case.

Check the PluginPathManager for methods that will help to work with such a directory.

1

Ah okay thank you for the clarification Jakub! 👍

0

Please sign in to leave a comment.