• I want to build a plugin in which I will use node and composer. Is this okay? How to make sure node and composer will work fine on any server?

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use them for development, but the production plugin should not.

    Thread Starter tempest47

    (@tempest47)

    So I must use only basic php and js.

    Your plugin can have a build process, but don’t include anything but the built part into the production plugin.

    Thread Starter tempest47

    (@tempest47)

    Can you give me an exemple? I am totally new to it? Should I never add a composer syntax in it?

    I can’t point to a plugin or theme as an example, since the ones in the repository don’t have it. But a lot of them are on GitHub, with build processes. The result of the build is what is put into the WP repository.
    I suppose Gutenberg could be an example. It comprises a lot of packages, that are released on npm, and also in core WP, and the test environment uses Node. But the scripts in the actual plugin don’t need Node since they run in the browser.
    I can’t speak to Composer, since I’ve never used it, but I know theme authors that do. The code that is in the plugin can’t rely on an environment that won’t exist on most sites.

    Edit: I went and read the Composer “Getting Started” page. Since it’s for pulling in dependencies, I don’t see why you would need it for a WP plugin. But then I think plugins should be small and do only one thing. If you are writing a large plugin, maybe you should reconsider what you are doing.

    • This reply was modified 4 years, 3 months ago by Joy.
    Thread Starter tempest47

    (@tempest47)

    I did not mean an example of a project that did it, I do not understand what you are referring to (i am still a beginner). I wanted something like a tutorial if you could find anything related.

    Let’s start again.

    How to make sure node and composer will work fine on any server?

    This question implies that you want to write code that specifically assumes that Node and Composer are needed on your user’s server. Don’t start with that assumption. Node is a way to run Javascript. A plugin for WP typically does not need that because the Javascript runs in the browser. If you want to run Javascript on the server, you are outside the bounds of WP and adding a requirement to the server that WP does not have.
    Composer is a PHP dependency manager. It is only used while developing your code, to get the latest versions of dependencies and generate the autoload code for them. It is not needed once the code is written, and is only really useful if you have a big codebase with lots of dependencies, so it should not really apply to most WP plugins.

    Now, if you simply want a project so you can learn to use Node and Composer, you can search for tutorials or read their documentation or join an existing project.
    But you don’t need either one to write a WP plugin.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Building a plugin using node and composer’ is closed to new replies.