chore:vite

This commit is contained in:
手瓜一十雪 2024-03-02 00:08:11 +08:00
parent 906fa4c382
commit 71ab1e6ff0
19 changed files with 1006 additions and 4518 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
node_modules/
package-lock.json
dist/
out/
.idea/
.DS_Store

View File

@ -1,10 +1,10 @@
{
"manifest_version": 4,
"type": "extension",
"name": "LLOneBot v3.11.0",
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "LiteLoaderQQNT的OneBotApi",
"version": "3.11.0",
"version": "3.7.0",
"thumbnail": "./icon.png",
"authors": [
{
@ -27,7 +27,7 @@
],
"injects": {
"renderer": "./renderer.js",
"main": "./main.js",
"preload": "./preload.js"
"main": "./main.cjs",
"preload": "./preload.cjs"
}
}
}

5300
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,13 @@
{
"name": "llonebot",
"version": "1.0.0",
"type": "module",
"description": "NTQQLiteLoaderOneBotApi",
"main": "dist/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run build-main && npm run build-preload && npm run build-renderer && npm run build-version",
"build-main": "webpack --config webpack.main.config.js",
"build-preload": "webpack --config webpack.preload.config.js",
"build-renderer": "webpack --config webpack.renderer.config.js",
"build-version": "ts-node ./scripts/gen-version.ts",
"build-mac": "npm run build && cp manifest.json dist/ && npm run deploy-mac",
"deploy-mac": "cp -r dist/* ~/Library/Containers/com.tencent.qq/Data/LiteLoaderQQNT/plugins/LLOnebot/",
"build-win": "npm run build && cp manifest.json dist/ && npm run deploy-win",
"deploy-win": "cmd /c \"copy dist\\* %USERPROFILE%\\documents\\LiteLoaderQQNT\\plugins\\LLOnebot\\\""
"build": "vite build",
"depend": "cd ./dist & npm install --omit=dev"
},
"author": "",
"license": "ISC",
@ -28,19 +22,14 @@
"ws": "^8.16.0"
},
"devDependencies": {
"@babel/preset-env": "^7.23.2",
"vite": "^4.4.9",
"vite-plugin-cp": "^4.0.8",
"@types/express": "^4.17.20",
"@types/fluent-ffmpeg": "^2.1.24",
"@types/node": "^20.11.24",
"@types/uuid": "^9.0.8",
"@types/ws": "^8.5.10",
"babel-loader": "^9.1.3",
"copy-webpack-plugin": "^12.0.2",
"electron": "^29.0.1",
"ts-loader": "^9.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
"typescript": "^5.2.2"
}
}

View File

@ -1,4 +1,4 @@
import * as path from "path";
import * as path from "node:path";
import {selfInfo} from "./data";
import {ConfigUtil} from "./config";
import util from "util";

View File

@ -1,7 +1,7 @@
// 运行在 Electron 主进程 下的插件入口
import {BrowserWindow, dialog, ipcMain} from 'electron';
import * as fs from 'fs';
import * as fs from 'node:fs';
import {Config} from "../common/types";
import {
CHANNEL_ERROR,

View File

@ -10,7 +10,7 @@ import {
} from "./types";
import {NTQQApi} from "./ntcall";
import {encodeSilk} from "../common/utils";
import * as fs from "fs";
import * as fs from "node:fs";
export class SendMsgElementConstructor {

View File

@ -17,7 +17,7 @@ import {
SendMessageElement,
User
} from "./types";
import * as fs from "fs";
import * as fs from "node:fs";
import {addHistoryMsg, friendRequests, groupNotifies, msgHistory, selfInfo} from "../common/data";
import {v4 as uuidv4} from "uuid"
import path from "path";

View File

@ -14,7 +14,7 @@ import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
import {uri2local} from "../utils";
import BaseAction from "./BaseAction";
import {ActionName, BaseCheckResult} from "./types";
import * as fs from "fs";
import * as fs from "node:fs";
import {log} from "../../common/utils";
import {decodeCQCode} from "../cqcode";

View File

@ -3,18 +3,18 @@ import {OB11Message} from "../types";
import {selfInfo} from "../../common/data";
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
import * as websocket from "ws";
import { WebSocket as WebSocketClass } from "ws";
import {wsReply} from "./ws/reply";
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
const eventWSList: websocket.WebSocket[] = [];
const eventWSList: WebSocketClass[] = [];
export function registerWsEventSender(ws: websocket.WebSocket) {
export function registerWsEventSender(ws: WebSocketClass) {
eventWSList.push(ws);
}
export function unregisterWsEventSender(ws: websocket.WebSocket) {
export function unregisterWsEventSender(ws: WebSocketClass) {
let index = eventWSList.indexOf(ws);
if (index !== -1) {
eventWSList.splice(index, 1);

View File

@ -1,6 +1,6 @@
import {getConfigUtil, log} from "../../../common/utils";
import * as WebSocket from "ws";
import {selfInfo} from "../../../common/data";
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
import {ActionName} from "../../action/types";
@ -9,11 +9,12 @@ import BaseAction from "../../action/BaseAction";
import {actionMap} from "../../action";
import {registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
import {wsReply} from "./reply";
import { WebSocket as WebSocketClass } from "ws";
export let rwsList: ReverseWebsocket[] = [];
export class ReverseWebsocket {
public websocket: WebSocket.WebSocket;
public websocket: WebSocketClass;
public url: string;
private running: boolean = false;
@ -76,7 +77,7 @@ export class ReverseWebsocket {
private connect() {
const {token} = getConfigUtil().getConfig()
this.websocket = new WebSocket.WebSocket(this.url, {
this.websocket = new WebSocketClass(this.url, {
handshakeTimeout: 2000,
perMessageDeflate: false,
headers: {

View File

@ -1,9 +1,9 @@
import * as websocket from "ws";
import { WebSocket as WebSocketClass } from "ws";
import {OB11Response} from "../../action/utils";
import {PostEventType} from "../postOB11Event";
import {isNull, log} from "../../../common/utils";
export function wsReply(wsClient: websocket.WebSocket, data: OB11Response | PostEventType) {
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
try {
let packet = Object.assign({
}, data);

View File

@ -1,6 +1,6 @@
import {CONFIG_DIR, isGIF} from "../common/utils";
import {v4 as uuidv4} from "uuid";
import * as path from 'path';
import * as path from 'node:path';
import {fileCache} from "../common/data";
const fs = require("fs").promises;

View File

@ -8,9 +8,11 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
// "sourceMap": true
// "sourceMap": true
},
"include": ["src/*"],
"include": [
"src/*"
],
"exclude": [
"node_modules",
"src/common/types.ts"

41
vite.config.ts Normal file
View File

@ -0,0 +1,41 @@
import { InlineConfig, defineConfig } from 'vite'
import { build } from "vite";
import cp from 'vite-plugin-cp';
import pkg from './package.json' assert { type: 'json' };
const externalAll = ["electron", "fs/promises", "fs", "url", "util", "path", /node:/, ...Object.keys(pkg.dependencies)];
console.log(externalAll);
function createConfig(library: string, path: string, emptyOutDir: boolean): InlineConfig {
return {
configFile: false,
build: {
emptyOutDir: emptyOutDir,
lib: {
formats: ["cjs"],
entry: { [library]: path }
},
rollupOptions: {
external: externalAll,
}
}
};
}
export function BuildPlugin() {
build(createConfig("main", "src/main/main.ts", false));
build(createConfig("preload", "src/preload.ts", false));
}
BuildPlugin();
export default defineConfig({
build: {
emptyOutDir: false,
lib: {
formats: ['es'],
entry: { ["renderer"]: `src/renderer.ts` },
},
rollupOptions: {
external: externalAll
}
},
plugins: [cp({ targets: [{ src: './package.json', dest: 'dist' }, { src: './manifest.json', dest: 'dist' }] })]
})

View File

@ -1,80 +0,0 @@
// import path from "path";
const webpack = require('webpack');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ignoreModules = [
"silk-wasm", "electron"
];
const copyModules = ["silk-wasm"]
let config = {
// target: 'node',
entry: {
// main: './src/main.ts',
// preload: './src/preload.ts'
}, // 入口文件路径
target: "node",
output: { // 输出文件配置
path: path.resolve(__dirname, 'dist'), // 输出目录路径
filename: '[name].js', // 输出文件名
// libraryTarget: "commonjs2",
// chunkFormat: "commonjs",
},
externals: ignoreModules,
experiments: {
// outputModule: true
// asyncWebAssembly: true
},
resolve: {
extensions: ['.js', '.ts']
},
module: { // 模块配置
rules: [ // 模块规则
{
test: /\.js$/, // 匹配.js文件
exclude: /node_modules/, // 排除node_modules目录
use: { // 使用的loader
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
}
}
},
{
test: /\.ts$/, // 匹配.ts文件
// exclude: /node_modules/, // 排除node_modules目录
use: { // 使用的loader
loader: 'ts-loader',
options: {
// configFile: 'src/tsconfig.json'
}
}
}]
},
optimization: {
minimize: false,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
plugins: [
new CopyPlugin({
patterns: copyModules.map(m => {
m = `node_modules/${m}`
return {
from: m,
to: m
}
})
}),
new webpack.DefinePlugin({
'process.env.FLUENTFFMPEG_COV': false,
}),
], // devtool: 'source-map',
}
module.exports = config

View File

@ -1,11 +0,0 @@
const baseConfig = require('./webpack.base.config.js')
baseConfig.target = 'electron-main'
baseConfig.entry = {
main: './src/main/main.ts',
// preload: './src/preload.ts',
}
baseConfig.output.libraryTarget = 'commonjs2'
baseConfig.output.chunkFormat = 'commonjs'
module.exports = baseConfig

View File

@ -1,9 +0,0 @@
const baseConfig = require('./webpack.base.config.js')
baseConfig.target = 'electron-preload'
baseConfig.entry = {
preload: './src/preload.ts',
}
baseConfig.output.chunkFormat = 'commonjs'
baseConfig.output.libraryTarget = 'commonjs2'
module.exports = baseConfig

View File

@ -1,11 +0,0 @@
const baseConfig = require('./webpack.base.config.js')
baseConfig.target = 'electron-renderer'
baseConfig.entry = {
renderer: './src/renderer.ts',
}
baseConfig.output.libraryTarget = 'module'
baseConfig.output.chunkFormat = 'module'
baseConfig.experiments.outputModule = true
module.exports = baseConfig