I was working with froala-editor package and i saw a plugin within the package file requiring the froala-editor itself like this: require(‘froala-editor’)
Here is link to that package: https://github.com/froala/wysiwyg-editor/blob/master/js/plugins/align.min.js
Here’s what i understand:
This code is written in UDM module system
the npm package name is froala-editor and inside the package code require(‘froala-editor’) is written.
It means when froala-editor is installed as package in some other project require(‘froala-editor’) will require the file which is mentioned in package.json as as the main file
If main: js/froala_editor.js is written.
Then require(“froala-editor”) will resolve to that file that is froala_editor.js file. Then whatever is exported from this will get reruired.
I need a little insight about how the codebase of package of this kind is written as well.
Thanks in advance.
I tried to implement similar thing using one main file and one plugin.
But i was not able to achieve this behaviour.
here’s link to my implementation .
when plugin file is imported the code should run smoothly but when it reaches the line where the package is requiring itself it fails.
error: ‘editor’ module not found