Skip to content

Commit

Permalink
Merge pull request #1853 from pt-plugins/dev_full_vite
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed May 12, 2024
2 parents 4ce8bb9 + dc72707 commit 38a99e4
Show file tree
Hide file tree
Showing 16 changed files with 842 additions and 1,050 deletions.
27 changes: 7 additions & 20 deletions package.json
Expand Up @@ -11,19 +11,14 @@
"displayName": "PT 助手 Plus",
"homepage": "https://github.com/pt-plugins/PT-Plugin-Plus",
"scripts": {
"build": "yarn build:background && yarn build:content && yarn build:index",
"lint": "eslint ./src/ --ext ts,vue,js",
"background": "webpack --config webpack/prod-background.cjs && webpack --config webpack/prod-content.cjs",
"dev": "yarn dev:background && yarn dev:content && yarn dev:index",
"dev-s": "cd debug && yarn install && tsc && node ./dist/index.js",
"build": "yarn build:index && yarn build:content && yarn build:background",
"dev:index": "vite build --watch",
"dev:background": "webpack --config webpack/dev-background.cjs --progress",
"dev:content": "webpack --config webpack/dev-content.cjs --progress",
"dev:bc": "yarn dev:background && yarn dev:content",
"resource": "cd debug && yarn install && tsc && node ./dist/buildResource.js",
"dev:background": "yarn build:background -- --mode development",
"dev:content": "yarn build:content -- --mode development",
"build:index": "vite build",
"build:background": "webpack --config webpack/prod-background.cjs --progress",
"build:content": "webpack --config webpack/prod-content.cjs --progress"
"build:background": "vite build --config vite.config.background.ts",
"build:content": "vite build --config vite.config.content.ts"
},
"dependencies": {
"basiccontext": "^3.5.1",
Expand All @@ -36,12 +31,9 @@
"file-saver": "^2.0.5",
"highcharts": "^10.2.1",
"highcharts-vue": "^1.4.0",
"https-browserify": "^1.0.0",
"i18next": "^21.9.1",
"jszip": "^3.10.1",
"parse-torrent": "^11.0.16",
"path-browserify": "^1.0.1",
"stream-http": "^3.2.0",
"ua-parser-js": "^1.0.2",
"url-parse": "^1.5.10",
"vue": "~2.7.0",
Expand Down Expand Up @@ -69,20 +61,15 @@
"@typescript-eslint/parser": "^7.7.1",
"@vitejs/plugin-vue2": "^2.3.1",
"@vue/eslint-config-typescript": "^13.0.0",
"copy-webpack-plugin": "^12.0.2",
"esbuild-loader": "^4.1.0",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.25.0",
"git-rev-sync": "^3.0.2",
"sass": "^1.75.0",
"sass-loader": "^14.2.1",
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vue-template-compiler": "~2.7.0",
"vuetify-loader": "~1.7.3",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0"
"vite-plugin-node-polyfills": "^0.21.0",
"vue-template-compiler": "~2.7.0"
},
"browserslist": [
"> 1%",
Expand Down
6 changes: 2 additions & 4 deletions public/manifest.json
Expand Up @@ -39,8 +39,7 @@
"libs/types.expand.js",
"libs/jquery/jquery-3.3.1.min.js",
"libs/Base64.js",
"js/background/libs.js",
"js/background/background.js"
"background/index.js"
]
},
"content_scripts": [{
Expand All @@ -65,8 +64,7 @@
"libs/notice/notice.js",
"libs/basicContext/basicContext.min.js",
"libs/drag.js",
"js/content/libs.js",
"js/content/content.js"
"contentScripts/index.js"
]
}],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
Expand Down
7 changes: 5 additions & 2 deletions resource/sites/springsunday.net/config.json
Expand Up @@ -177,8 +177,7 @@
"searchEntryConfig": {
"fieldSelector": {
"subTitle": {
"selector": ["div.torrent-smalldescr:first"],
"filters": ["query.prop('lastChild').nodeValue.trim()"]
"selector": ["div.torrent-smalldescr:first > span"]
},
"progress": {
"selector": [".p_seeding", ".p_downloading", ".p_completed", ".p_inactive", ""],
Expand Down Expand Up @@ -222,6 +221,10 @@
}, {
"name": "⛔️",
"selector": "span.torrent-exclusive"
}, {
"name": "MiniDB",
"color": "amber",
"selector": "span.torrent-minibd"
}],
"selectors": {
"userBaseInfo": {
Expand Down
13 changes: 0 additions & 13 deletions src/options/shims-tsx.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/service/api.ts
Expand Up @@ -12,7 +12,7 @@ import "./favicon";

let rootPath = "";
let isExtensionMode = false;
const isDebugMode = process.env.NODE_ENV === "development";
const isDebugMode = import.meta.env.DEV;
// 检测浏览器当前状态和模式
try {
let runtime = chrome.runtime as any;
Expand Down
2 changes: 2 additions & 0 deletions src/options/shims-vue.d.ts → src/shims-env.d.ts
@@ -1,3 +1,5 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import Vue from 'vue'
export default Vue
Expand Down
46 changes: 46 additions & 0 deletions vite.config.background.ts
@@ -0,0 +1,46 @@
import path from 'node:path'
import {defineConfig} from 'vite'
import {sharedConfig} from "./vite.config";
import fs from "node:fs";
import git from 'git-rev-sync'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import buildResource from "./vite/buildResource";

// https://vitejs.dev/config/
export default defineConfig({
...sharedConfig,
build: {
outDir: path.resolve(__dirname, 'dist/background'),
lib: {
entry: path.resolve(__dirname, 'src/background/index.ts'),
name: 'background',
formats: ['iife']
},
rollupOptions: {
output: {
entryFileNames: 'index.js',
extend: true,
},
},
chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
emptyOutDir: false,
copyPublicDir: false
},
plugins: [
nodePolyfills({
include: ['path'],
}),
buildResource(),
{
name: 'update_manifest_version',
closeBundle() {
const manifest_file_path = path.resolve(__dirname, './dist/manifest.json');
const manifest = JSON.parse(fs.readFileSync(manifest_file_path, 'utf-8'));
const build_number = git.count() % 65535;
manifest.version = `${manifest.version}.${build_number}`;

fs.writeFileSync(manifest_file_path, JSON.stringify(manifest, null, 2));
},
}
]
})
31 changes: 31 additions & 0 deletions vite.config.content.ts
@@ -0,0 +1,31 @@
import path from 'node:path'
import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import {sharedConfig} from "./vite.config";

// https://vitejs.dev/config/
export default defineConfig({
...sharedConfig,
build: {
outDir: path.resolve(__dirname, 'dist/contentScripts'),
lib: {
entry: path.resolve(__dirname, 'src/content/index.ts'),
name: 'content',
formats: ['iife']
},
rollupOptions: {
output: {
entryFileNames: 'index.js',
extend: true,
},
},
chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
emptyOutDir: false,
copyPublicDir: false
},
plugins: [
nodePolyfills({
include: ['path'],
}),
]
})
35 changes: 12 additions & 23 deletions vite.config.ts
@@ -1,37 +1,26 @@
import { fileURLToPath, URL } from 'node:url'
import fs from 'node:fs'
import path from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue2'
import git from 'git-rev-sync'
import buildResource from "./vite/buildResource";

export const sharedConfig = {
publicDir: 'public',
resolve: {
extensions: ['.ts', '.js', '.tsx', '.vue'],
alias: {
'@': fileURLToPath(new URL('src', import.meta.url))
},
},
}

// https://vitejs.dev/config/
export default defineConfig({
...sharedConfig,
publicDir: 'public',
build: {
chunkSizeWarningLimit: 0,
chunkSizeWarningLimit: Number.MAX_SAFE_INTEGER,
emptyOutDir: false
},
plugins: [
vue(),
buildResource(),
{
name: 'update_manifest_version',
closeBundle() {
const manifest_file_path = path.resolve(__dirname, './dist/manifest.json');
const manifest = JSON.parse(fs.readFileSync(manifest_file_path, 'utf-8'));
const build_number = git.count() % 65535;
manifest.version = `${manifest.version}.${build_number}`;

fs.writeFileSync(manifest_file_path, JSON.stringify(manifest, null, 2));
},
}
],
resolve: {
extensions: ['.ts', '.js', '.tsx', '.vue'],
alias: {
'@': fileURLToPath(new URL('src', import.meta.url))
},
},
})
16 changes: 16 additions & 0 deletions vite/buildResource.ts
Expand Up @@ -7,6 +7,21 @@ export default function buildResource() {
const resourcePath = PATH.resolve(__dirname, '..', './dist/resource');
const resourceMap = ["sites", "schemas", "clients", "publicSites"];

/**
* 将resource目录复制到dist下
*/
function prepareResource() {
const rawResourcePath = PATH.resolve(__dirname, '..', './resource');
FS.cpSync(rawResourcePath, resourcePath, {
recursive: true, filter(source: string, destination: string) {
if (source.endsWith("README.md")) {
return false;
}
return true;
}
});
}

/**
* 创建资源文件列表
*/
Expand Down Expand Up @@ -260,6 +275,7 @@ export default function buildResource() {
return {
name: 'build_resource',
buildEnd() {
prepareResource();
buildResource();
getSupportedSites();
}
Expand Down
81 changes: 0 additions & 81 deletions webpack/common.cjs

This file was deleted.

0 comments on commit 38a99e4

Please sign in to comment.