mirror of
https://github.com/Anarios/return-youtube-dislike.git
synced 2026-09-12 10:22:10 +02:00
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
|
|
const path = require("path");
|
||
|
|
const webpack = require("webpack");
|
||
|
|
const userscriptMeta = require("./Extensions/UserScript/userscript.meta");
|
||
|
|
const { LiveBuildMarkerPlugin, createLiveBuildId } = require("./webpack.live-build-marker");
|
||
|
|
|
||
|
|
function buildUserscriptBanner(liveTestBuild) {
|
||
|
|
const metadata = [
|
||
|
|
"// ==UserScript==",
|
||
|
|
`// @name ${userscriptMeta.name}${liveTestBuild ? " [Live Test]" : ""}`,
|
||
|
|
`// @namespace ${userscriptMeta.namespace}`,
|
||
|
|
`// @homepage ${userscriptMeta.homepage}`,
|
||
|
|
`// @version ${userscriptMeta.version}`,
|
||
|
|
`// @encoding ${userscriptMeta.encoding}`,
|
||
|
|
`// @description ${userscriptMeta.description}`,
|
||
|
|
`// @icon ${userscriptMeta.icon}`,
|
||
|
|
`// @author ${userscriptMeta.author}`,
|
||
|
|
...userscriptMeta.match.map((value) => `// @match ${value}`),
|
||
|
|
...userscriptMeta.exclude.map((value) => `// @exclude ${value}`),
|
||
|
|
...userscriptMeta.compatible.map((value) => `// @compatible ${value}`),
|
||
|
|
...(liveTestBuild
|
||
|
|
? []
|
||
|
|
: [`// @downloadURL ${userscriptMeta.downloadURL}`, `// @updateURL ${userscriptMeta.updateURL}`]),
|
||
|
|
...userscriptMeta.grants.map((value) => `// @grant ${value}`),
|
||
|
|
`// @run-at ${userscriptMeta.runAt}`,
|
||
|
|
"// ==/UserScript==",
|
||
|
|
"",
|
||
|
|
"// This file is generated by `npm run build:userscript`.",
|
||
|
|
"// Edit Extensions/UserScript/src instead of the generated file.",
|
||
|
|
];
|
||
|
|
|
||
|
|
return metadata.join("\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = (env = {}, argv = {}) => {
|
||
|
|
const liveTestBuild = env.liveTest === true || env.liveTest === "true";
|
||
|
|
const liveBuildId = createLiveBuildId(liveTestBuild);
|
||
|
|
|
||
|
|
return {
|
||
|
|
name: "userscript",
|
||
|
|
mode: argv.mode ?? "production",
|
||
|
|
entry: path.resolve(__dirname, "Extensions/UserScript/src/userscript-entry.js"),
|
||
|
|
output: {
|
||
|
|
path: liveTestBuild
|
||
|
|
? path.resolve(__dirname, "test-results/live-build/userscript")
|
||
|
|
: path.resolve(__dirname, "Extensions/UserScript"),
|
||
|
|
filename: "Return Youtube Dislike.user.js",
|
||
|
|
clean: false,
|
||
|
|
iife: true,
|
||
|
|
},
|
||
|
|
cache: false,
|
||
|
|
optimization: {
|
||
|
|
minimize: false,
|
||
|
|
},
|
||
|
|
plugins: [
|
||
|
|
new webpack.DefinePlugin({
|
||
|
|
__RYD_LIVE_BUILD_ID__: JSON.stringify(liveBuildId),
|
||
|
|
__RYD_LIVE_TEST_BUILD__: JSON.stringify(liveTestBuild),
|
||
|
|
}),
|
||
|
|
...(liveTestBuild ? [new LiveBuildMarkerPlugin(liveBuildId, ["live-build.json"])] : []),
|
||
|
|
new webpack.BannerPlugin({
|
||
|
|
banner: buildUserscriptBanner(liveTestBuild),
|
||
|
|
raw: true,
|
||
|
|
entryOnly: true,
|
||
|
|
}),
|
||
|
|
],
|
||
|
|
devtool: false,
|
||
|
|
performance: {
|
||
|
|
hints: false,
|
||
|
|
},
|
||
|
|
};
|
||
|
|
};
|