mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: remove static manifest
This commit is contained in:
1 parent
10c3a62168
commit
d7412fcc1e
18 files changed
+50
-124
No files matched your search
@@ -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' })] : [],
|
||||
],
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user