node.js - How to include javascript for both main process and renderer -


in electron project, i've found if put javascript module.exports in node_modules folder can access both main process , renderer process require() either place.

is correct method of accessing common javascript, or there different best-practice?

assume there's no particular reason needs node module- global configuration object.

similarly- aside messier folder structure, there practical ramifications method vs. linking via <script> tags in renderer process? (in case assuming in 1 folder, keep simple)

is correct method of accessing common javascript, or there different best-practice?

this indeed how should loading node modules, of script files (or third-party libs) may not written modules. when node integration enabled can load modules node_modules, source directory, or app asar using require.

similarly- aside messier folder structure, there practical ramifications method vs. linking via <script> tags in renderer process?

<script> tags shove global namespace, can useful in cases, , browser libs (like jquery) expect loaded way. shouldn't loading node modules via <script src="path/to/module.js">, though it's reasonable call require within <script> tag.


Comments