mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-04 22:27:10 -04:00
Added minify
This commit is contained in:
parent
856908219d
commit
6d73fed7b6
4 changed files with 77 additions and 63 deletions
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const eejs = require('../../eejs');
|
||||
const eejs = require('../../eejs')
|
||||
const fs = require('fs');
|
||||
const fsp = fs.promises;
|
||||
const toolbar = require('../../utils/toolbar');
|
||||
|
@ -9,7 +9,8 @@ const hooks = require('../../../static/js/pluginfw/hooks');
|
|||
const settings = require('../../utils/Settings');
|
||||
const util = require('util');
|
||||
const webaccess = require('./webaccess');
|
||||
|
||||
const plugins = require('../../../static/js/pluginfw/plugin_defs');
|
||||
import {buildSync} from 'esbuild'
|
||||
exports.expressPreSession = async (hookName:string, {app}:any) => {
|
||||
// This endpoint is intended to conform to:
|
||||
// https://www.ietf.org/archive/id/draft-inadarei-api-health-check-06.html
|
||||
|
@ -73,12 +74,40 @@ exports.expressPreSession = async (hookName:string, {app}:any) => {
|
|||
});
|
||||
};
|
||||
|
||||
exports.expressCreateServer = (hookName:string, args:any, cb:Function) => {
|
||||
exports.expressCreateServer = async (hookName: string, args: any, cb: Function) => {
|
||||
// serve index.html under /
|
||||
args.app.get('/', (req: any, res: any) => {
|
||||
res.send(eejs.require('ep_etherpad-lite/templates/index.html', {req}));
|
||||
});
|
||||
|
||||
await fsp.writeFile(
|
||||
path.join(settings.root, 'var/js/padbootstrap.js'),
|
||||
eejs.require('ep_etherpad-lite/templates/padBootstrap.js', {
|
||||
pluginModules: (() => {
|
||||
const pluginModules = new Set();
|
||||
for (const part of plugins.parts) {
|
||||
for (const [, hookFnName] of Object.entries(part.client_hooks || {})) {
|
||||
pluginModules.add(hookFnName.split(':')[0]);
|
||||
}
|
||||
}
|
||||
return [...pluginModules];
|
||||
})(),
|
||||
settings,
|
||||
}));
|
||||
|
||||
const result = buildSync({
|
||||
entryPoints: [settings.root + "/src/templates/padBootstrap.js"], // Entry file(s)
|
||||
bundle: true, // Bundle the files together
|
||||
minify: true, // Minify the output
|
||||
sourcemap: true, // Generate source maps
|
||||
sourceRoot: settings.root+"/src/static/js/",
|
||||
target: ['es2020'], // Target ECMAScript version
|
||||
write: false, // Do not write to file system,
|
||||
})
|
||||
|
||||
const textResult = result.outputFiles[0].text
|
||||
|
||||
|
||||
// serve pad.html under /p
|
||||
args.app.get('/p/:pad', (req: any, res: any, next: Function) => {
|
||||
// The below might break for pads being rewritten
|
||||
|
|
|
@ -441,68 +441,13 @@
|
|||
<!----------------------------->
|
||||
|
||||
<% e.begin_block("scripts"); %>
|
||||
|
||||
<script type="text/javascript" src="../static/js/require-kernel.js?v=<%=settings.randomVersionString%>"></script>
|
||||
<script type="text/javascript" src="../socket.io/socket.io.js"></script>
|
||||
|
||||
<!-- Include base packages manually (this help with debugging) -->
|
||||
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
||||
<script type="text/javascript" src="../javascripts/lib/ep_etherpad-lite/static/js/ace2_common.js?callback=require.define&v=<%=settings.randomVersionString%>"></script>
|
||||
<script src="<%=entrypoint%>"></script>
|
||||
|
||||
<% e.begin_block("customScripts"); %>
|
||||
<script type="text/javascript" src="../static/skins/<%=encodeURI(settings.skinName)%>/pad.js?v=<%=settings.randomVersionString%>"></script>
|
||||
<% e.end_block(); %>
|
||||
|
||||
<!-- Bootstrap page -->
|
||||
<script type="text/javascript">
|
||||
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt
|
||||
var clientVars = {
|
||||
// This is needed to fetch /pluginfw/plugin-definitions.json, which happens before the
|
||||
// server sends the CLIENT_VARS message.
|
||||
randomVersionString: <%-JSON.stringify(settings.randomVersionString)%>,
|
||||
};
|
||||
(function () {
|
||||
var pathComponents = location.pathname.split('/');
|
||||
|
||||
// Strip 'p' and the padname from the pathname and set as baseURL
|
||||
var baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/';
|
||||
|
||||
require.setRootURI(baseURL + "javascripts/src");
|
||||
require.setLibraryURI(baseURL + "javascripts/lib");
|
||||
require.setGlobalKeyPath("require");
|
||||
|
||||
$ = jQuery = require('ep_etherpad-lite/static/js/rjquery').jQuery; // Expose jQuery #HACK
|
||||
browser = require('ep_etherpad-lite/static/js/vendors/browser');
|
||||
|
||||
var plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins');
|
||||
var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
|
||||
|
||||
plugins.baseURL = baseURL;
|
||||
plugins.update(function () {
|
||||
// Mechanism for tests to register hook functions (install fake plugins).
|
||||
window._postPluginUpdateForTestingDone = false;
|
||||
if (window._postPluginUpdateForTesting != null) window._postPluginUpdateForTesting();
|
||||
window._postPluginUpdateForTestingDone = true;
|
||||
// Call documentReady hook
|
||||
$(function() {
|
||||
hooks.aCallAll('documentReady');
|
||||
});
|
||||
|
||||
var pad = require('ep_etherpad-lite/static/js/pad');
|
||||
pad.baseURL = baseURL;
|
||||
pad.init();
|
||||
});
|
||||
|
||||
/* TODO: These globals shouldn't exist. */
|
||||
pad = require('ep_etherpad-lite/static/js/pad').pad;
|
||||
chat = require('ep_etherpad-lite/static/js/chat').chat;
|
||||
padeditbar = require('ep_etherpad-lite/static/js/pad_editbar').padeditbar;
|
||||
padimpexp = require('ep_etherpad-lite/static/js/pad_impexp').padimpexp;
|
||||
require('ep_etherpad-lite/static/js/skin_variants');
|
||||
|
||||
}());
|
||||
// @license-end
|
||||
</script>
|
||||
<div style="display:none"><a href="/javascript" data-jslicense="1">JavaScript license information</a></div>
|
||||
<% e.end_block(); %>
|
||||
</body>
|
||||
|
|
40
src/templates/padBootstrap.js
Normal file
40
src/templates/padBootstrap.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
(async () => {
|
||||
window.clientVars = {
|
||||
// This is needed to fetch /pluginfw/plugin-definitions.json, which happens before the server
|
||||
// sends the CLIENT_VARS message.
|
||||
randomVersionString: <%-JSON.stringify(settings.randomVersionString)%>,
|
||||
};
|
||||
|
||||
// Allow other frames to access this frame's modules.
|
||||
window.require.resolveTmp = require.resolve('ep_etherpad-lite/static/js/pad_cookie');
|
||||
|
||||
const basePath = new URL('..', window.location.href).pathname;
|
||||
window.$ = window.jQuery = require('../../src/static/js/rjquery').jQuery;
|
||||
window.browser = require('../../src/static/js/vendors/browser');
|
||||
const pad = require('../../src/static/js/pad');
|
||||
pad.baseURL = basePath;
|
||||
window.plugins = require('../../src/static/js/pluginfw/client_plugins');
|
||||
const hooks = require('../../src/static/js/pluginfw/hooks');
|
||||
|
||||
// TODO: These globals shouldn't exist.
|
||||
window.pad = pad.pad;
|
||||
window.chat = require('../../src/static/js/chat').chat;
|
||||
window.padeditbar = require('../../src/static/js/pad_editbar').padeditbar;
|
||||
window.padimpexp = require('../../src/static/js/pad_impexp').padimpexp;
|
||||
require('../../src/static/js/skin_variants');
|
||||
|
||||
window.plugins.baseURL = basePath;
|
||||
await window.plugins.update(new Map([
|
||||
<% for (const module of pluginModules) { %>
|
||||
[<%- JSON.stringify(module) %>, require(<%- JSON.stringify(module) %>)],
|
||||
<% } %>
|
||||
]));
|
||||
// Mechanism for tests to register hook functions (install fake plugins).
|
||||
window._postPluginUpdateForTestingDone = false;
|
||||
if (window._postPluginUpdateForTesting != null) window._postPluginUpdateForTesting();
|
||||
window._postPluginUpdateForTestingDone = true;
|
||||
window.pluginDefs = require('../../src/static/js/pluginfw/plugin_defs');
|
||||
pad.init();
|
||||
await new Promise((resolve) => $(resolve));
|
||||
await hooks.aCallAll('documentReady');
|
||||
})();
|
0
var/js/.gitignore
vendored
Normal file
0
var/js/.gitignore
vendored
Normal file
Loading…
Add table
Add a link
Reference in a new issue