core&ui: remove static manifest

This commit is contained in:
undefined committed 2021-09-15 17:28:57 +08:00
1 parent 10c3a62168
commit d7412fcc1e
18 files changed
+50 -124

No files matched your search

@@ -115,9 +115,6 @@ nunjucks.runtime.memberLookup = function memberLookup(obj, val) {
const env = new Nunjucks();
env.addGlobal('static_url', (assetName) => {
const cdnPrefix = process.env.DEV ? '/' : global.Hydro.model.system.get('server.cdn');
if (global.Hydro.ui.manifest[assetName]) {
return `${cdnPrefix}${global.Hydro.ui.manifest[assetName]}`;
}
return `${cdnPrefix}${assetName}`;
});
// eslint-disable-next-line no-eval
@@ -12,7 +12,6 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import SpeedMeasurePlugin from 'speed-measure-webpack-plugin';
import WebpackBar from 'webpackbar';
import mapWebpackUrlPrefix from '../utils/mapWebpackUrlPrefix';
import StaticManifestPlugin from '../plugins/manifest.webpack';
import root from '../utils/root';
const beautifyOutputUrl = mapWebpackUrlPrefix([
@@ -237,13 +236,6 @@ export default function (env = {}) {
},
}],
}),
new StaticManifestPlugin({
fileName: 'static-manifest.json',
ignore: [
'img/emoji/',
'katex/',
],
}),
...env.measure ? [new BundleAnalyzerPlugin({ analyzerPort: 'auto' })] : [],
],
};
+3
View File
@@ -76,6 +76,9 @@ async function main() {
await runWebpack(argv.options);
if (argv.options.production) {
fs.removeSync('public/vditor/dist/js/mathjax');
fs.removeSync('public/vditor/dist/js/echarts');
fs.removeSync('public/vditor/dist/js/graphviz');
fs.removeSync('public/vditor/dist/js/mermaid');
fs.removeSync('public/vditor/dist/js/abcjs');
}
process.chdir(dir);
@@ -1,49 +0,0 @@
/* eslint-disable import/no-extraneous-dependencies */
const _ = require('lodash');
const crypto = require('crypto');
export default class StaticManifestPlugin {
constructor({ fileName, ignore }) {
this.fileName = fileName;
this.ignore = ignore;
}
apply(compiler) {
compiler.hooks.emit.tap('sync', (compilation) => {
const stats = compilation.getStats().toJson();
const manifest = _(stats.assets)
.map((asset) => {
const { name } = asset;
// Skip files listed in ignore
if (_.some(this.ignore, (ignorePattern) => name.indexOf(ignorePattern) > -1)) {
return null;
}
// Skip calculating hash for names like ?xxxx
if (name.indexOf('?') > -1) {
return [
name.replace(/\?[\s\S]*/, ''), // origin name
name, // name with hash
];
}
// We need to calculate hash for the remaining files.
const source = compilation.assets[asset.name].source();
const shasum = crypto.createHash('sha1');
shasum.update(source);
const hash = shasum.digest('hex').substr(0, 10);
return [
name, // origin name
`${name}?${hash}`, // name with hash
];
})
.filter()
.orderBy(['0'])
.fromPairs()
.value();
const json = JSON.stringify(manifest, null, 2);
compilation.assets[this.fileName] = {
source: () => json,
size: () => json.length,
};
});
}
}
+5 -8
View File
@@ -1,9 +1,8 @@
/* eslint-disable no-return-await */
/* eslint-disable camelcase */
import crypto from 'crypto';
import { readdir, readFile } from 'fs-extra';
import { readFileSync } from 'fs-extra';
import { join } from 'path';
import { tmpdir } from 'os';
import { ObjectID } from 'mongodb';
import * as bus from 'hydrooj/src/service/bus';
import { Route, Handler } from 'hydrooj/src/service/server';
@@ -31,8 +30,10 @@ declare module 'hydrooj/src/interface' {
const cache = {};
const coll = db.collection('cache');
const pages = Object.keys(global.ui.manifest)
.filter((file) => file.endsWith('.page.js'))
.map((i) => readFileSync(join(global.ui.manifest[i], i), 'utf-8'));
const basedir = join(tmpdir(), 'hydro', 'public');
async function constant(args: ConstantArgs) {
// CompileLangs
const payload = [`window.LANGS=${JSON.stringify(setting.langs)};`];
@@ -64,11 +65,7 @@ async function constant(args: ConstantArgs) {
}` : ''}\`;
document.body.appendChild(e);`;
const files = await readdir(basedir);
const pages = files
.filter((file) => file.endsWith('.page.js'))
.map((i) => readFile(join(basedir, i), 'utf-8'));
payload.push(...await Promise.all(pages));
payload.push(...pages);
const c = crypto.createHash('sha1');
c.update(JSON.stringify(payload));
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.20.8",
"version": "4.21.0",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",