mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-20 15:30:39 +01:00
fix: fix taskbar warning
add app.importScript copy public/src/modules to build folder
This commit is contained in:
@@ -334,9 +334,13 @@ ajaxify.widgets = { render: render };
|
||||
};
|
||||
|
||||
ajaxify.loadScript = function (tpl_url, callback) {
|
||||
let location = !app.inAdmin ? 'forum/' : '';
|
||||
if (tpl_url.startsWith('admin')) {
|
||||
location = '';
|
||||
}
|
||||
const data = {
|
||||
tpl_url: tpl_url,
|
||||
scripts: [tpl_url],
|
||||
scripts: [location + tpl_url],
|
||||
};
|
||||
|
||||
// Hint: useful if you want to load a module on a specific page (append module name to `scripts`)
|
||||
@@ -354,7 +358,7 @@ ajaxify.widgets = { render: render };
|
||||
}
|
||||
if (typeof script === 'string') {
|
||||
return async function (next) {
|
||||
const module = await importScript(script);
|
||||
const module = await app.importScript(script);
|
||||
// Hint: useful if you want to override a loaded library (e.g. replace core client-side logic),
|
||||
// or call a method other than .init()
|
||||
hooks.fire('static:script.init', { tpl_url, name: script, module }).then(() => {
|
||||
@@ -383,25 +387,6 @@ ajaxify.widgets = { render: render };
|
||||
});
|
||||
};
|
||||
|
||||
async function importScript(scriptName) {
|
||||
let pageScript;
|
||||
try {
|
||||
if (scriptName.startsWith('admin/plugins')) {
|
||||
pageScript = await import(/* webpackChunkName: "admin/plugins/[request]" */ 'admin/plugins/' + scriptName.replace(/^admin\/plugins\//, ''));
|
||||
} else if (scriptName.startsWith('admin')) {
|
||||
pageScript = await import(/* webpackChunkName: "admin/[request]" */ 'admin/' + scriptName.replace(/^admin\//, ''));
|
||||
} else if (scriptName.startsWith('forum/plugins')) {
|
||||
pageScript = await import(/* webpackChunkName: "forum/plugins/[request]" */ 'forum/plugins/' + scriptName.replace(/^forum\/plugins\//, ''));
|
||||
} else {
|
||||
pageScript = await import(/* webpackChunkName: "forum/[request]" */ 'forum/' + scriptName);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('error loading script' + err.stack);
|
||||
}
|
||||
return pageScript;
|
||||
}
|
||||
|
||||
|
||||
ajaxify.loadData = function (url, callback) {
|
||||
url = ajaxify.removeRelativePath(url);
|
||||
|
||||
|
||||
@@ -49,6 +49,26 @@ app.flags = {};
|
||||
}
|
||||
};
|
||||
|
||||
app.importScript = async function (scriptName) {
|
||||
let pageScript;
|
||||
try {
|
||||
if (scriptName.startsWith('admin/plugins')) {
|
||||
pageScript = await import(/* webpackChunkName: "admin/plugins/[request]" */ 'admin/plugins/' + scriptName.replace(/^admin\/plugins\//, ''));
|
||||
} else if (scriptName.startsWith('admin')) {
|
||||
pageScript = await import(/* webpackChunkName: "admin/[request]" */ 'admin/' + scriptName.replace(/^admin\//, ''));
|
||||
} else if (scriptName.startsWith('forum/plugins')) {
|
||||
pageScript = await import(/* webpackChunkName: "forum/plugins/[request]" */ 'forum/plugins/' + scriptName.replace(/^forum\/plugins\//, ''));
|
||||
} else if (scriptName.startsWith('forum')) {
|
||||
pageScript = await import(/* webpackChunkName: "forum/[request]" */ 'forum/' + scriptName.replace(/^forum\//, ''));
|
||||
} else {
|
||||
pageScript = await import(/* webpackChunkName: "modules/[request]" */ '../../build/public/src/modules/' + scriptName);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('error loading script' + err.stack);
|
||||
}
|
||||
return pageScript && pageScript.default;
|
||||
}
|
||||
|
||||
app.handleEarlyClicks = function () {
|
||||
/**
|
||||
* Occasionally, a button or anchor (not meant to be ajaxified) is clicked before
|
||||
|
||||
@@ -7,9 +7,9 @@ import * as autocomplete from 'autocomplete';
|
||||
import 'jquery-deserialize';
|
||||
import * as api from 'api';
|
||||
import * as alerts from 'alerts';
|
||||
|
||||
export function init() {
|
||||
console.log('should be true semver.gt("1.1.1", "1.0.0")', semver.gt('1.1.1', '1.0.0'));
|
||||
|
||||
$('#change-skin').val(config.bootswatchSkin);
|
||||
|
||||
$('#inputTags').tagsinput({
|
||||
@@ -98,4 +98,7 @@ export function init() {
|
||||
|
||||
document.head.appendChild(linkEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const testPage = { init };
|
||||
export default testPage;
|
||||
@@ -12,26 +12,22 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
|
||||
self.tasklist = self.taskbar.find('ul');
|
||||
$(document.body).append(self.taskbar);
|
||||
|
||||
self.taskbar.on('click', 'li', function () {
|
||||
self.taskbar.on('click', 'li', async function () {
|
||||
const $btn = $(this);
|
||||
const moduleName = $btn.attr('data-module');
|
||||
const uuid = $btn.attr('data-uuid');
|
||||
|
||||
// TODO: throws warning in webpack
|
||||
// https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import
|
||||
require([moduleName], function (module) {
|
||||
if (!$btn.hasClass('active')) {
|
||||
minimizeAll();
|
||||
module.load(uuid);
|
||||
taskbar.toggleNew(uuid, false);
|
||||
|
||||
taskbar.tasklist.removeClass('active');
|
||||
$btn.addClass('active');
|
||||
} else {
|
||||
module.minimize(uuid);
|
||||
}
|
||||
});
|
||||
const module = await app.importScript(moduleName);
|
||||
if (!$btn.hasClass('active')) {
|
||||
minimizeAll();
|
||||
module.load(uuid);
|
||||
taskbar.toggleNew(uuid, false);
|
||||
|
||||
taskbar.tasklist.removeClass('active');
|
||||
$btn.addClass('active');
|
||||
} else {
|
||||
module.minimize(uuid);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
@@ -41,22 +37,21 @@ define('taskbar', ['benchpress', 'translator', 'hooks'], function (Benchpress, t
|
||||
});
|
||||
};
|
||||
|
||||
taskbar.close = function (module, uuid) {
|
||||
taskbar.close = async function (moduleName, uuid) {
|
||||
// Sends signal to the appropriate module's .close() fn (if present)
|
||||
const btnEl = taskbar.tasklist.find('[data-module="' + module + '"][data-uuid="' + uuid + '"]');
|
||||
let fnName = 'close';
|
||||
|
||||
// TODO: Refactor chat module to not take uuid in close instead of by jQuery element
|
||||
if (module === 'chat') {
|
||||
if (moduleName === 'chat') {
|
||||
fnName = 'closeByUUID';
|
||||
}
|
||||
|
||||
if (btnEl.length) {
|
||||
require([module], function (module) {
|
||||
if (typeof module[fnName] === 'function') {
|
||||
module[fnName](uuid);
|
||||
}
|
||||
});
|
||||
const module = await app.importScript(moduleName);
|
||||
if (module && typeof module[fnName] === 'function') {
|
||||
module[fnName](uuid);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ exports.webpack = async function (options) {
|
||||
if (options.watch) {
|
||||
stats = await webpackWatch(webpackCfg.watchOptions);
|
||||
compiler.hooks.assetEmitted.tap('nbbWatchPlugin', (file) => {
|
||||
console.log(`webpack:assetEmitted > ${webpackCfg.output.publicPath} ${file}`);
|
||||
console.log(`webpack:assetEmitted > ${webpackCfg.output.publicPath}${file}`);
|
||||
});
|
||||
} else {
|
||||
stats = await webpackRun();
|
||||
|
||||
@@ -134,6 +134,13 @@ async function clearModules() {
|
||||
|
||||
JS.buildModules = async function () {
|
||||
await clearModules();
|
||||
|
||||
const fse = require('fs-extra');
|
||||
await fse.copy(
|
||||
path.join(__dirname, `../../public/src/modules`),
|
||||
path.join(__dirname, `../../build/public/src/modules`)
|
||||
);
|
||||
|
||||
await linkModules();
|
||||
};
|
||||
|
||||
|
||||
@@ -28,21 +28,18 @@ module.exports = {
|
||||
},
|
||||
output: {
|
||||
filename: '[name].bundle.js',
|
||||
chunkFilename: '[name].bundle.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
publicPath: `${relativePath}/dist/`,
|
||||
},
|
||||
watchOptions: {
|
||||
poll: 500,
|
||||
aggregateTimeout: 500,
|
||||
aggregateTimeout: 250,
|
||||
},
|
||||
resolve: {
|
||||
symlinks: false,
|
||||
modules: [
|
||||
'build/public/src/modules',
|
||||
'public/src',
|
||||
'public/src/modules',
|
||||
'public/src/client',
|
||||
'node_modules',
|
||||
...activePlugins.map(p => `node_modules/${p}/node_modules`),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user