• Swedes

    Migrating to NodeBB v2 I came across an issue that I cannot resolve. In my theme/plugin I override two scripts because I want to write my own logic for two pages:

    • register
    • email

    I get this error:

    uncaughtException: EEXIST: file already exists, symlink '../../../../node_modules/[PLUGIN/THEME NAME]/lib/client/register.js'

    Any ideas on how to get around this?

  • GNU/Linux Admin

    @baris Instead of overriding the file, you can name the file whatever you want, and use filter:script.load on the client-side to remove the call to the built-in module, and insert your own.

    hooks.on('filter:script.load', (data) => {
      console.log(data.tpl_url, data.scripts);
    });
    
  • NodeBB Admin

    Do you want to completely replace the logic on register page? Can you post a sample from your plugin.json?

    I think the suggested way to do this is to use modules section.

  • GNU/Linux Admin

    @baris Instead of overriding the file, you can name the file whatever you want, and use filter:script.load on the client-side to remove the call to the built-in module, and insert your own.

    hooks.on('filter:script.load', (data) => {
      console.log(data.tpl_url, data.scripts);
    });
    
  • Topic has been marked as solved  magnusvhendin magnusvhendin 
  • Swedes

    @julian This worked great. I did this in my main client file (like persona.js).

    require(['hooks'], (hooks) => {
    	hooks.on('filter:script.load', (data) => {
    		const replaceMap = {
    			register: {
    				target: 'forum/register',
    				with: 'replacement/register',
    			},
    		};
    
    		const replace = replaceMap[data.tpl_url];
    
    		if (replace) {
    			const index = data.scripts.indexOf(replace.target);
    			if (index > -1) data.scripts[index] = replace.with;
    			else data.scripts.push(replace.with);
    		}
    
    		return data;
    	});
    });
    

    Then I can just add my scripts that I want to replace to the replaceMap object.


Suggested Topics

| | |

© 2014 – 2022 NodeBB, Inc. — Made in Canada.