Serve libraries from node_modules.
This commit is contained in:
parent
766c301a44
commit
b8faf1f78b
@ -35,6 +35,9 @@ var ROOT_DIR = path.normalize(__dirname + "/../../static/");
|
|||||||
var TAR_PATH = path.join(__dirname, 'tar.json');
|
var TAR_PATH = path.join(__dirname, 'tar.json');
|
||||||
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
|
var tar = JSON.parse(fs.readFileSync(TAR_PATH, 'utf8'));
|
||||||
|
|
||||||
|
|
||||||
|
var LIBRARY_WHITELIST = [];
|
||||||
|
|
||||||
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
// Rewrite tar to include modules with no extensions and proper rooted paths.
|
||||||
var LIBRARY_PREFIX = 'ep_etherpad-lite/static/js';
|
var LIBRARY_PREFIX = 'ep_etherpad-lite/static/js';
|
||||||
exports.tar = {};
|
exports.tar = {};
|
||||||
@ -131,20 +134,26 @@ function minify(req, res, next)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle static files for plugins:
|
/* Handle static files for plugins/libraries:
|
||||||
paths like "plugins/ep_myplugin/static/js/test.js"
|
paths like "plugins/ep_myplugin/static/js/test.js"
|
||||||
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js,
|
||||||
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
||||||
*/
|
*/
|
||||||
var match = filename.match(/^plugins\/([^\/]+)\/static\/(.*)/);
|
var match = filename.match(/^plugins\/([^\/]+)(\/(?:(static\/.*)|.*))?$/);
|
||||||
if (match) {
|
if (match) {
|
||||||
var pluginName = match[1];
|
var library = match[1];
|
||||||
var resourcePath = match[2];
|
var libraryPath = match[2] || '';
|
||||||
var plugin = plugins.plugins[pluginName];
|
|
||||||
if (plugin) {
|
if (plugins.plugins[library] && match[3]) {
|
||||||
|
var plugin = plugins.plugins[library];
|
||||||
var pluginPath = plugin.package.realPath;
|
var pluginPath = plugin.package.realPath;
|
||||||
filename = path.relative(ROOT_DIR, pluginPath + '/static/' + resourcePath);
|
filename = path.relative(ROOT_DIR, pluginPath + libraryPath);
|
||||||
filename = filename.replace(/\\/g, '/'); // Windows (safe generally?)
|
filename = filename.replace(/\\/g, '/'); // Windows (safe generally?)
|
||||||
|
} else if (LIBRARY_WHITELIST.indexOf(library) != -1) {
|
||||||
|
// Go straight into node_modules
|
||||||
|
// Avoid `require.resolve()`, since 'mustache' and 'mustache/index.js'
|
||||||
|
// would end up resolving to logically distinct resources.
|
||||||
|
filename = '../node_modules/' + library + libraryPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user