grafana/scripts/webpack/plugins/CopyUniconsPlugin.js
Jack Westbrook 78bef7a26a
Build: Enable long term caching for frontend assets (#47625)
* build(webpack): move CopyUniconsPlugin into own file

* chore(webpack): delete unused blobUrl and compile loaders

* build(webpack): prefer contenthash over fullhash for longer caching

* build(webpack): set optimization.moduleIds named only in dev

* build(webpack): introduce HTMLWebpackCSSChunks so templates can access theme css by name

* feat: inject css files with contenthash in html templates

* revert(error-template): remove ContentDeliveryURL from CSS href

* refactor(index-template): update grafanaBootData.themePaths

* chore(webpack): add typescript annotations for CopyUniconsPlugin
2022-05-26 11:49:18 +02:00

40 lines
1.1 KiB
JavaScript

const fs = require('fs-extra');
const path = require('path');
class CopyUniconsPlugin {
/**
* @param {import('webpack').Compiler} compiler
*/
apply(compiler) {
compiler.hooks.afterEnvironment.tap(
'CopyUniconsPlugin',
/**
* @param {import('webpack').Compilation} compilation
*/
() => {
let destDir = path.resolve(__dirname, '../../../public/img/icons/unicons');
if (!fs.pathExistsSync(destDir)) {
let srcDir = path.join(
path.dirname(require.resolve('iconscout-unicons-tarball/package.json')),
'unicons/svg/line'
);
fs.copySync(srcDir, destDir);
}
let solidDestDir = path.resolve(__dirname, '../../../public/img/icons/solid');
if (!fs.pathExistsSync(solidDestDir)) {
let srcDir = path.join(
path.dirname(require.resolve('iconscout-unicons-tarball/package.json')),
'unicons/svg/solid'
);
fs.copySync(srcDir, solidDestDir);
}
}
);
}
}
module.exports = CopyUniconsPlugin;