Write a plugin with node modules for NW.js

2
  • 5 favourites

Index

Stats

4,447 visits, 7,360 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Requirements

You will need :

- Winrar

- NodeJS

Choosing your module

You can find modules on the npm page. Just make a search and it will give you all the packages availables.

For example, I choosed to implement a color picker -> npm link

Preparing to be ready

Export once your project as-is, then go to the folder.

Open a console, then write : npm init to make this folder npm compatible.

Then type in the console : npm i simple-color-picker to install the color picker (replace it with the command specified for your module on the npm page)

Now you are ready, you code your plugin.

Plugin creation

Develop your plugin as you do it usually.

When using require, do not use absolute path. You just have to use require("simple-color-picker");

Make it all work together

When your plugin is ready, make your stuff inside C2.

Then export the game again and go to the folder.

Now, it's the important part.

Navigate to the win32 folder, for example.

If you try to execute nw.exe, as usal, it will not work, because even if the node_module folder is there, nw.exe search for the ressources inside the package.nw

So, what we should do ?

You can rename the file exetension to zip, then open it and import the node_module folder to it.

But, if you have winrar, you can also open a command (or make a bat script) and type in :

"C:\Program Files\WinRAR\WinRAR.exe" a -afzip -r -u "package.nw" "node_modules/"

It will simply add node_modules folder to package.nw.

After adding node_modules to your package.zip, rename back package.zip to package.nw

Try to execute again !

Not working too.

Rename your package.json file to package.json.old because it is interfering with the start script.

(If someone have a fix for that, without renaming package.json ;))

No all is fine :)

Conclusion

Yes, that's cool. but caution : Some package will not work.

About C++ package, I have tried rebuilding them (because you need it) but unsuccessfull each time :( (i'm w10), do you have the same pb ?

I hope you guys enjoy :)

Hoping to see node plugin ;)

You can download the example binary here

  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!