bugfix:尝试修复路径问题

This commit is contained in:
li1553770945 2025-06-13 21:12:49 +08:00
parent 54826eda62
commit dfb70785e0
4 changed files with 213 additions and 187 deletions

View File

@ -1,51 +1,50 @@
//@ts-check import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
'use strict'; // 适配 ESM 的 __dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const path = require('path'); /** @type {import('webpack').Configuration} */
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
const extensionConfig = { const extensionConfig = {
target: 'node', // VS Code extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/ target: 'node', // VS Code 扩展运行于 Node.js 环境
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') mode: 'none', // 保持代码原样,打包时设为 'production'
entry: resolve(__dirname, 'src', 'extension.ts'), // 绝对路径
output: {
path: resolve(__dirname, 'dist'), // 绝对路径
filename: 'extension.js',
libraryTarget: 'module', // 改为 ESM 兼容的模块格式
chunkFormat: 'module', // 确保分块也是 ESM 格式
},
externals: {
vscode: 'commonjs vscode', // 排除 vscode 模块
// 其他需排除的依赖(如第三方库)
},
experiments: {
outputModule: true, // 启用 ESM 输出实验性功能
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
bufferutil: false,
'utf-8-validate': false
}
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader'
}]
}
]
},
devtool: 'nosources-source-map',
infrastructureLogging: {
level: 'log'
}
};
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ export default [extensionConfig];
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
},
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
// modules added here also need to be added in the .vscodeignore file
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js'],
fallback: {
bufferutil: false,
'utf-8-validate': false
}
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
},
devtool: 'nosources-source-map',
infrastructureLogging: {
level: "log", // enables logging required for problem matchers
},
}; module.exports = [extensionConfig];

View File

@ -2,62 +2,70 @@ import { defineConfig, normalizePath } from 'vite';
import { resolve } from 'path'; import { resolve } from 'path';
import { viteStaticCopy } from 'vite-plugin-static-copy'; import { viteStaticCopy } from 'vite-plugin-static-copy';
// 统一定义根目录,确保路径一致性
const rootDir = resolve(__dirname, '..');
const srcDir = resolve(rootDir, 'renderer/src');
const outDir = resolve(rootDir, 'openmcp-sdk');
export default defineConfig({ export default defineConfig({
define: { define: {
'window': { 'window': {
'nodejs': true, 'nodejs': true,
'navigator': { 'navigator': {
'userAgent': 2 'userAgent': 2
}, },
'performance': { 'performance': {
'now': () => performance.now() 'now': () => performance.now()
}, },
'Date': { 'Date': {
'now': () => Date.now() 'now': () => Date.now()
} }
},
}, },
plugins: [ },
viteStaticCopy({ plugins: [
targets: [ viteStaticCopy({
{ targets: [
src: normalizePath(resolve(__dirname, '../resources/openmcp-sdk-release/*')), {
dest: normalizePath(resolve(__dirname, '../openmcp-sdk')) // 使用统一路径处理逻辑
} src: normalizePath(resolve(rootDir, 'resources/openmcp-sdk-release/*')),
] dest: normalizePath(outDir)
})
],
build: {
target: 'node18',
lib: {
entry: resolve(__dirname, '..', 'renderer/src/components/main-panel/chat/core/task-loop.ts'),
name: 'TaskLoop',
fileName: 'task-loop',
formats: ['cjs']
},
outDir: resolve(__dirname, '..', 'openmcp-sdk'),
emptyOutDir: false,
rollupOptions: {
external: [
'vue',
'chalk',
'element-plus',
],
output: {
globals: {
vue: 'vue',
chalk: 'chalk',
'element-plus': './tools.js'
},
esModule: true
}
},
minify: false,
sourcemap: false
},
resolve: {
alias: {
'@': resolve(__dirname, '..', 'renderer/src'),
} }
]
})
],
build: {
target: 'node18',
lib: {
// 使用统一路径变量
entry: resolve(srcDir, 'components/main-panel/chat/core/task-loop.ts'),
name: 'TaskLoop',
fileName: 'task-loop',
formats: ['es'] // 改为 ESM 格式 [[7]]
},
outDir, // 使用统一输出目录
emptyOutDir: false,
rollupOptions: {
external: [
'vue',
'chalk',
'element-plus',
],
output: {
globals: {
vue: 'vue',
chalk: 'chalk',
'element-plus': './tools.js' // 使用 POSIX 风格路径 [[10]]
},
esModule: true
}
},
minify: false,
sourcemap: false
},
resolve: {
alias: {
// 使用统一路径变量
'@': srcDir
} }
}); }
});

View File

@ -1,80 +1,90 @@
const path = require('path'); import { fileURLToPath } from 'url';
const TerserPlugin = require('terser-webpack-plugin'); import { dirname, resolve } from 'path';
const webpack = require('webpack'); import TerserPlugin from 'terser-webpack-plugin';
const CopyWebpackPlugin = require('copy-webpack-plugin'); import webpack from 'webpack';
import CopyWebpackPlugin from 'copy-webpack-plugin';
module.exports = { // 适配 ESM 的 __dirname
mode: 'development', // 设置为 development 模式 const __filename = fileURLToPath(import.meta.url);
devtool: 'source-map', // 生成 source map 以便调试 const __dirname = dirname(__filename);
entry: './renderer/src/components/main-panel/chat/core/task-loop.ts',
output: { // 统一路径变量
path: path.resolve(__dirname, '../openmcp-sdk'), const rootDir = resolve(__dirname, '..');
filename: 'task-loop.js', const srcDir = resolve(rootDir, 'renderer/src');
libraryTarget: 'commonjs2' const outDir = resolve(rootDir, 'openmcp-sdk');
export default {
mode: 'development',
devtool: 'source-map',
entry: resolve(srcDir, 'components/main-panel/chat/core/task-loop.ts'),
output: {
path: outDir,
filename: 'task-loop.js',
libraryTarget: 'commonjs', // 改为 ESM 兼容的 commonjs 格式 [[9]]
},
target: 'node',
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@': srcDir,
}, },
target: 'node', },
resolve: { module: {
extensions: ['.ts', '.js'], rules: [
alias: { {
'@': path.resolve(__dirname, '../renderer/src'), // 修正路径别名 test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
configFile: resolve(rootDir, 'tsconfig.json'),
},
}, },
}, exclude: /node_modules/,
module: { },
rules: [ {
{ test: /\.vue$/,
test: /\.ts$/, use: {
use: { loader: 'null-loader',
loader: 'ts-loader', },
options: { },
configFile: path.resolve(__dirname, '../tsconfig.json') // 指定 tsconfig.json 路径
}
},
exclude: /node_modules/,
},
{
test: /\.vue$/,
use: {
loader: 'null-loader'
}
}
],
},
optimization: {
minimize: true, // Enable code compression
minimizer: [
new TerserPlugin({
extractComments: false, // Disable extracting license files
terserOptions: {
compress: {
drop_console: true, // Remove all console.* calls
},
},
}),
],
},
plugins: [
new webpack.DefinePlugin({
window: {
nodejs: true,
navigator: {
userAgent: 2
},
performance: {
now: () => Date.now()
}
}
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, '../resources/openmcp-sdk-release'),
to: path.resolve(__dirname, '../openmcp-sdk')
}
]
})
], ],
externals: { },
vue: 'vue', // 不打包 vue 库 optimization: {
'element-plus': './tools.js' minimize: true,
}, minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
},
plugins: [
new webpack.DefinePlugin({
window: {
nodejs: true,
navigator: {
userAgent: 2,
},
performance: {
now: () => Date.now(),
},
},
}),
new CopyWebpackPlugin({
patterns: [
{
from: resolve(rootDir, 'resources/openmcp-sdk-release'),
to: outDir,
},
],
}),
],
externals: {
vue: 'vue',
'element-plus': './tools.js', // 使用 POSIX 风格路径 [[6]]
},
}; };

View File

@ -1,18 +1,27 @@
const path = require('path'); import { fileURLToPath } from 'url';
const CopyWebpackPlugin = require('copy-webpack-plugin'); import { dirname, resolve } from 'path';
import CopyWebpackPlugin from 'copy-webpack-plugin';
module.exports = { // 适配 ESM 的 __dirname
entry: './node_modules/tesseract.js/src/worker-script/node/index.js', const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// 统一路径变量
const rootDir = resolve(__dirname, '..');
const outDir = resolve(rootDir, 'resources', 'ocr');
export default {
entry: resolve(rootDir, 'node_modules', 'tesseract.js', 'src', 'worker-script', 'node', 'index.js'),
output: { output: {
path: path.resolve(__dirname, '..', 'resources', 'ocr'), path: outDir,
filename: 'worker.js', filename: 'worker.js',
libraryTarget: 'commonjs2' libraryTarget: 'commonjs', // 改为 ESM 兼容的 commonjs 格式
}, },
resolve: { resolve: {
fallback: { fallback: {
bufferutil: false, bufferutil: false,
'utf-8-validate': false 'utf-8-validate': false,
} },
}, },
mode: 'production', mode: 'production',
target: 'node', target: 'node',
@ -20,8 +29,8 @@ module.exports = {
new CopyWebpackPlugin({ new CopyWebpackPlugin({
patterns: [ patterns: [
{ {
from: path.resolve(__dirname, '..', 'node_modules', 'tesseract.js-core', 'tesseract*'), from: resolve(rootDir, 'node_modules', 'tesseract.js-core', 'tesseract*'),
to: path.resolve(__dirname, '..', 'resources', 'ocr', '[name][ext]'), to: resolve(outDir, '[name][ext]'),
}, },
], ],
}), }),