Upgrade to Webpack 5 and other cleanup

next v0.7.6
neobooru 2021-10-15 21:57:28 +02:00
parent a82a46699d
commit 120ffb123e
14 changed files with 1042 additions and 3238 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "szuru-chrome", "name": "szuru-chrome",
"version": "0.7.5", "version": "0.7.6",
"description": "Import media from various sites into szurubooru.", "description": "Import media from various sites into szurubooru.",
"author": "neobooru", "author": "neobooru",
"license": "MIT", "license": "MIT",
@ -8,39 +8,32 @@
"url": "https://github.com/neobooru/SzuruChrome" "url": "https://github.com/neobooru/SzuruChrome"
}, },
"scripts": { "scripts": {
"build": "cross-env NODE_ENV=production webpack --hide-modules", "build": "webpack --config webpack.prod.js",
"build:dev": "cross-env NODE_ENV=development webpack --hide-modules", "build:dev": "webpack --config webpack.dev.js",
"build-zip": "node scripts/build-zip.js", "build-zip": "node scripts/build-zip.js",
"sign-xpi": "node scripts/sign-xpi.js", "sign-xpi": "node scripts/sign-xpi.js",
"watch": "npm run build -- --watch", "watch": "webpack --watch --config webpack.dev.js"
"watch:dev": "cross-env HMR=true npm run build:dev -- --watch"
}, },
"dependencies": { "dependencies": {
"axios": "^0.21.1", "axios": "^0.23.0",
"neo-scraper": "^0.4.7", "neo-scraper": "^0.4.7",
"vue": "^2.6.11", "vue": "^2.6.14",
"webextension-polyfill": "^0.3.1" "webextension-polyfill": "^0.8.0"
}, },
"devDependencies": { "devDependencies": {
"archiver": "^3.1.1", "archiver": "^5.3.0",
"autodll-webpack-plugin": "^0.4.2", "copy-webpack-plugin": "^9.0.1",
"copy-webpack-plugin": "^5.1.1", "css-loader": "^6.4.0",
"core-js": "^3.6.5", "mini-css-extract-plugin": "^2.4.2",
"cross-env": "^5.2.1", "sign-addon": "^3.9.0",
"css-loader": "^2.1.1", "ts-loader": "^9.2.6",
"file-loader": "^1.1.11", "typescript": "^4.4.4",
"mini-css-extract-plugin": "^0.4.4", "vue-loader": "^15.9.8",
"node-sass": "^4.14.1", "vue-template-compiler": "^2.6.14",
"sass-loader": "^7.3.1", "web-ext-types": "^3.2.1",
"sign-addon": "^3.5.0", "webextension-polyfill-ts": "^0.26.0",
"ts-loader": "^6.2.2", "webpack": "^5.58.2",
"typescript": "^3.9.7", "webpack-cli": "^4.9.0",
"vue-loader": "^15.9.3",
"vue-template-compiler": "^2.6.11",
"web-ext-types": "^2.1.0",
"webextension-polyfill-ts": "^0.9.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12",
"webpack-extension-reloader": "^1.1.4" "webpack-extension-reloader": "^1.1.4"
} }
} }

View File

@ -126,6 +126,7 @@ export default class SzuruWrapper {
private async execute(config: AxiosRequestConfig): Promise<any> { private async execute(config: AxiosRequestConfig): Promise<any> {
if (this.username && this.authToken) { if (this.username && this.authToken) {
const token = "Token " + btoa(`${this.username}:${this.authToken}`); const token = "Token " + btoa(`${this.username}:${this.authToken}`);
if (!config.headers) config.headers = {};
config.headers["Authorization"] = token; config.headers["Authorization"] = token;
} }

View File

@ -16,11 +16,11 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": ["<all_urls>"], "matches": ["<all_urls>"],
"js": ["vendor.dll.js", "scripts/content.js"] "js": ["vendor.js", "scripts/content.js"]
} }
], ],
"background": { "background": {
"scripts": ["vendor.dll.js", "scripts/background.js"] "scripts": ["vendor.js", "scripts/background.js"]
}, },
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {

View File

@ -8,7 +8,7 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="../vendor.dll.js"></script> <script src="../vendor.js"></script>
<script src="options.js"></script> <script src="options.js"></script>
</body> </body>
</html> </html>

View File

@ -1,7 +1,7 @@
import "../css/style.css"; import "../css/style.css";
import Vue from "vue"; import Vue from "vue";
import App from "./App"; import App from "./App.vue";
new Vue({ new Vue({
el: "#app", el: "#app",

View File

@ -109,16 +109,18 @@
</div> </div>
<div class="popup-section"> <div class="popup-section">
<img :src="selectedPost.contentUrl" v-if="selectedPost.contentType == 'image'" />
<video v-if="selectedPost.contentType == 'video'" controls>
<source :src="selectedPost.contentUrl" />
</video>
<div style="display: flex"> <div style="display: flex">
<button class="primary" @click="findSimilar">Find similar</button> <button class="primary" @click="findSimilar">Find similar</button>
<button class="primary full" style="margin-left: 5px" @click="upload">Import</button> <button class="primary full" style="margin-left: 5px" @click="upload">Import</button>
</div> </div>
</div> </div>
<div class="popup-section">
<img :src="selectedPost.contentUrl" v-if="selectedPost.contentType == 'image'" />
<video v-if="selectedPost.contentType == 'video'" controls>
<source :src="selectedPost.contentUrl" />
</video>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -260,7 +262,7 @@ export default Vue.extend({
}, },
// Open extension settings page in new tab // Open extension settings page in new tab
async openSettings() { async openSettings() {
const url = browser.extension.getURL("options/options.html"); const url = browser.runtime.getURL("options/options.html");
window.open(url); window.open(url);
}, },
getTagClasses(tag: TagViewModel): string[] { getTagClasses(tag: TagViewModel): string[] {

View File

@ -8,7 +8,7 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="../vendor.dll.js"></script> <script src="../vendor.js"></script>
<script src="popup.js"></script> <script src="popup.js"></script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@ import "../css/fontawesome.css";
import "../css/solid.css"; import "../css/solid.css";
import Vue from "vue"; import Vue from "vue";
import App from "./App"; import App from "./App.vue";
new Vue({ new Vue({
el: "#app", el: "#app",

View File

@ -9,12 +9,8 @@
"skipLibCheck": true, "skipLibCheck": true,
"esModuleInterop": true, "esModuleInterop": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"lib": [ "useUnknownInCatchVariables": false,
"es2019", "lib": ["es2019", "dom"]
"dom"
]
}, },
"include": [ "include": ["./src/**/*"]
"./src/**/*"
]
} }

117
webpack.common.js Normal file
View File

@ -0,0 +1,117 @@
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const ExtensionReloader = require("webpack-extension-reloader");
const { VueLoaderPlugin } = require("vue-loader");
const { version } = require("./package.json");
module.exports = {
context: __dirname + "/src",
entry: {
"scripts/content": { import: "./scripts/content.ts", dependOn: "vendor" },
"scripts/background": { import: "./scripts/background.ts", dependOn: "vendor" },
"popup/popup": { import: "./popup/popup.ts", dependOn: "vendor" },
"options/options": { import: "./options/options.ts", dependOn: "vendor" },
vendor: ["axios", "neo-scraper", "vue", "webextension-polyfill-ts"]
},
output: {
path: __dirname + "/dist",
filename: "[name].js"
},
resolve: {
extensions: [".ts", ".js", ".vue"]
},
module: {
rules: [
{
test: /\.vue$/,
loader: "vue-loader"
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|jpg|gif|svg|ico)$/,
type: "asset/resource",
generator: {
filename: "[name][ext]"
}
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
type: "asset/resource",
generator: {
filename: "fonts/[name][ext]"
}
}
]
},
plugins: [
new webpack.DefinePlugin({
global: "window"
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new CopyPlugin({
patterns: [
{ from: "icons", to: "icons" },
{ from: "popup/popup.html", to: "popup/popup.html" },
{ from: "options/options.html", to: "options/options.html" },
{
from: "manifest.json",
to: "manifest.json",
transform: content => {
const jsonContent = JSON.parse(content);
jsonContent.version = version;
// if (config.mode === "development") {
// jsonContent["content_security_policy"] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
// }
return JSON.stringify(jsonContent, null, 2);
}
}
]
})
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false
})
]
}
};
// if (config.mode === "production") {
// config.plugins = (config.plugins || []).concat([
// new webpack.DefinePlugin({
// "process.env": {
// NODE_ENV: '"production"'
// }
// })
// ]);
// }
// if (process.env.HMR === "true") {
// config.plugins = (config.plugins || []).concat([
// new ExtensionReloader({
// entries: {
// contentScript: "scripts/content",
// background: "scripts/background"
// }
// })
// ]);
// }

View File

@ -1,121 +0,0 @@
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtensionReloader = require("webpack-extension-reloader");
const AutoDllPlugin = require("autodll-webpack-plugin");
const { VueLoaderPlugin } = require("vue-loader");
const { version } = require("./package.json");
const config = {
mode: process.env.NODE_ENV,
context: __dirname + "/src",
entry: {
"scripts/content": "./scripts/content.ts",
"scripts/background": "./scripts/background.ts",
"popup/popup": "./popup/popup.ts",
"options/options": "./options/options.ts"
},
output: {
path: __dirname + "/dist",
filename: "[name].js"
},
resolve: {
extensions: [".ts", ".js", ".vue"]
},
performance: {
hints: false
},
devtool: "inline-source-map",
module: {
rules: [
{
test: /\.vue$/,
loaders: "vue-loader"
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/]
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|jpg|gif|svg|ico)$/,
loader: "file-loader",
options: {
name: "[name].[ext]?emitFile=false"
}
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader",
options: {
name: "[name].[ext]?emitFile=false",
outputPath: "/fonts/"
}
}
]
},
plugins: [
new webpack.DefinePlugin({
global: "window"
}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new CopyWebpackPlugin([
{ from: "icons", to: "icons", ignore: ["icon.xcf"] },
{ from: "popup/popup.html", to: "popup/popup.html" },
{ from: "options/options.html", to: "options/options.html" },
{
from: "manifest.json",
to: "manifest.json",
transform: content => {
const jsonContent = JSON.parse(content);
jsonContent.version = version;
if (config.mode === "development") {
jsonContent["content_security_policy"] = "script-src 'self' 'unsafe-eval'; object-src 'self'";
}
return JSON.stringify(jsonContent, null, 2);
}
}
]),
new AutoDllPlugin({
filename: "[name].dll.js",
entry: {
vendor: ["vue", "neo-scraper", "webextension-polyfill-ts"]
}
})
]
};
if (config.mode === "production") {
config.plugins = (config.plugins || []).concat([
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: '"production"'
}
})
]);
}
if (process.env.HMR === "true") {
config.plugins = (config.plugins || []).concat([
new ExtensionReloader({
entries: {
contentScript: "scripts/content",
background: "scripts/background"
}
})
]);
}
module.exports = config;

7
webpack.dev.js Normal file
View File

@ -0,0 +1,7 @@
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
});

6
webpack.prod.js Normal file
View File

@ -0,0 +1,6 @@
const { merge } = require('webpack-merge');
const common = require("./webpack.common.js");
module.exports = merge(common, {
mode: "production"
});

3945
yarn.lock

File diff suppressed because it is too large Load Diff