mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-09-12 09:58:20 +02:00
137 lines
3.8 KiB
JavaScript
137 lines
3.8 KiB
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
|
|
|
const extensionVersion = process.env.npm_package_version.replace("-", ".");
|
|
const entries = ["ryd.content-script", "ryd.background", "popup", "ryd.changelog"];
|
|
|
|
const ignorePatterns = [
|
|
"**/manifest-**",
|
|
"**/dist/**",
|
|
"**/src/**",
|
|
"**/readme.md",
|
|
...entries.map((entry) => `**/${entry}.js`),
|
|
];
|
|
|
|
const manifestTransform = (content, filename) => {
|
|
const filteredContent = content
|
|
.toString()
|
|
.split("\n")
|
|
.filter((str) => !str.trimStart().startsWith("//"))
|
|
.join("\n");
|
|
|
|
const manifestData = JSON.parse(filteredContent);
|
|
manifestData.version = extensionVersion;
|
|
return JSON.stringify(manifestData, null, 2);
|
|
};
|
|
|
|
const i18nTransform = (content, filename) => {
|
|
if (!filename.endsWith("messages.json")) return content;
|
|
|
|
return content.toString().replace(/__RYD_VERSION__/g, extensionVersion);
|
|
};
|
|
|
|
class MirrorJsOutputsPlugin {
|
|
constructor(targetDirs) {
|
|
this.targetDirs = targetDirs;
|
|
}
|
|
|
|
apply(compiler) {
|
|
compiler.hooks.afterEmit.tapPromise("MirrorJsOutputsPlugin", async () => {
|
|
const { promises: fsp } = fs;
|
|
const outputPath = compiler.options.output.path;
|
|
const entries = await fsp.readdir(outputPath).catch(() => []);
|
|
const jsAssets = entries.filter((name) => name.endsWith(".js"));
|
|
|
|
await Promise.all(
|
|
this.targetDirs.map(async (dir) => {
|
|
const targetDir = path.join(outputPath, dir);
|
|
await fsp.mkdir(targetDir, { recursive: true });
|
|
|
|
const existingFiles = await fsp.readdir(targetDir).catch(() => []);
|
|
await Promise.all(
|
|
existingFiles
|
|
.filter((file) => file.endsWith(".js"))
|
|
.map((file) => fsp.rm(path.join(targetDir, file), { force: true }))
|
|
);
|
|
|
|
await Promise.all(
|
|
jsAssets.map((asset) =>
|
|
fsp.copyFile(path.join(outputPath, asset), path.join(targetDir, path.basename(asset))),
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = (env, argv) => ({
|
|
entry: Object.fromEntries(
|
|
entries.map((entry) => [entry, path.join(__dirname, "./Extensions/combined/", `${entry}.js`)]),
|
|
),
|
|
output: {
|
|
filename: "[name].js",
|
|
path: path.resolve(__dirname, "Extensions/combined/dist"),
|
|
clean: true,
|
|
},
|
|
cache: false,
|
|
optimization: {
|
|
minimize: false,
|
|
},
|
|
watchOptions: {
|
|
ignored: "**/dist/**",
|
|
},
|
|
plugins: [
|
|
// exclude locale files in moment
|
|
new CopyPlugin({
|
|
patterns: [
|
|
{
|
|
from: "./Extensions/combined",
|
|
to: "./chrome",
|
|
globOptions: {
|
|
ignore: ignorePatterns,
|
|
},
|
|
transform: i18nTransform,
|
|
},
|
|
{
|
|
from: "./Extensions/combined/manifest-chrome.json",
|
|
to: "./chrome/manifest.json",
|
|
transform: manifestTransform,
|
|
},
|
|
{
|
|
from: "./Extensions/combined",
|
|
to: "./firefox",
|
|
globOptions: {
|
|
ignore: ignorePatterns,
|
|
},
|
|
transform: i18nTransform,
|
|
},
|
|
{
|
|
from: "./Extensions/combined/manifest-firefox.json",
|
|
to: "./firefox/manifest.json",
|
|
transform: manifestTransform,
|
|
},
|
|
{
|
|
from: "./Extensions/combined",
|
|
to: "./safari",
|
|
globOptions: {
|
|
ignore: ignorePatterns,
|
|
},
|
|
transform: i18nTransform,
|
|
},
|
|
{
|
|
from: "./Extensions/combined/manifest-safari.json",
|
|
to: "./safari/manifest.json",
|
|
transform: manifestTransform,
|
|
},
|
|
],
|
|
}),
|
|
new MirrorJsOutputsPlugin(["chrome", "firefox", "safari"]),
|
|
],
|
|
experiments: {
|
|
topLevelAwait: true,
|
|
},
|
|
devtool: argv.mode === "development" ? "inline-source-map" : false,
|
|
});
|