vscode 插件開發(fā) + vue的操作方法
如果我們需要在vscode中嵌入自己開發(fā)的vue頁面就需要以下的操作
1.把開發(fā)好的vue項目打包,如果打包出來的vue執(zhí)行是空白頁,就需要看看之前我寫的文章,vue 3 clie打包配置
-這里要注意的是,要確保vue項目里面的public有一個index用作插件打開時的模板,等一下需要做base的特?fù)Q,不然插件是不知道網(wǎng)頁的根目錄在哪里
index.html
-vue.config.js的配置
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <link rel="icon" href="<%= BASE_URL %>favicon.ico"> <title>Test</title> <base href="/"> </head> <body> <div id="app"></div> </body> </html>
-vue.config.js的配置
const path = require('path');
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
// 基本路徑
publicPath: './',
// 輸出文件目錄
outputDir: 'dist',
pages: {
index: {
entry: 'src/main.js',
template: 'public/index.html',
filename: 'index.html',
chunks: ['chunk-vendors', 'chunk-common', 'index']
}
},
lintOnSave:false,
configureWebpack: {
externals: {
}
},
chainWebpack: (config)=>{
//修改文件引入自定義路徑
config.resolve.alias
.set('@', resolve('src'))
.set('~assets',resolve('src/assets'))
// .set('ide',resolve('src/ide'))
}
}
2.把打包好的整個dist考到vscode插件里面
-vscode插件的命令行觸發(fā)函數(shù)里面,需要這樣寫
const panel = vscode.window.createWebviewPanel(
'testWebview', // viewType
"WebView演示", // 視圖標(biāo)題
vscode.ViewColumn.One, // 顯示在編輯器的哪個部位
{
enableScripts: true, // 啟用JS,默認(rèn)禁用
retainContextWhenHidden: true, // webview被隱藏時保持狀態(tài),避免被重置
}
);
//加載本地html頁面
let srcPath = path.join(context.extensionPath, 'dist');
// console.log(srcPath)
const srcPathUri = vscode.Uri.file(srcPath);
// console.log(srcPathUri.path)
const baseUri = panel.webview.asWebviewUri(srcPathUri);
// console.log(baseUri)
const indexPath = path.join(srcPath, 'index.html');
// console.log(indexPath)
var indexHtml = fs.readFileSync(indexPath, "utf8");
indexHtml = indexHtml.replace('<base href=/ >', `<base href="${String(baseUri)}/">`);
// console.log(indexHtml)
panel.webview.html = indexHtml;
這樣,打開的頁面就能正確顯示
總結(jié)
到此這篇關(guān)于vscode 插件開發(fā) + vue的操作方法的文章就介紹到這了,更多相關(guān)vscode 插件開發(fā) vue內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element自定義表單驗證上傳身份證正反面的實現(xiàn)
表單驗證在很多地方都可以用的到,本文主要介紹了element自定義表單驗證上傳身份證正反面的實現(xiàn),文中根據(jù)實例編碼詳細(xì)介紹的十分詳盡,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03
vue使用富文本編輯器vue-quill-editor的操作指南和注意事項
vue中很多項目都需要用到富文本編輯器,在使用了ueditor和tinymce后,發(fā)現(xiàn)并不理想,所以果斷使用vue-quill-editor來實現(xiàn),下面這篇文章主要給大家介紹了關(guān)于vue使用富文本編輯器vue-quill-editor的操作指南和注意事項,需要的朋友可以參考下2023-05-05
Vue-router 報錯NavigationDuplicated的解決方法
這篇文章主要介紹了Vue-router 報錯NavigationDuplicated的解決方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
前端vue?uni-app?cc-countdown倒計時組件使用詳解
cc-countdown是一個倒計時組件,它可以顯示剩余時間、天數(shù)、小時數(shù)、分鐘數(shù)和秒數(shù),在本文中,我們將介紹如何在uni-app中使用cc-countdown組件,需要的朋友可以參考下2023-08-08

