Unable to override scripts
-
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
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?
-
@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); });
-
@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); });
-
-
@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.