Pug 拦截器失败:错误:方案已被截获



我使用electron-forge创建了一个Electron应用程序。 在这个应用程序中,我想渲染pug(Jade)模板,所以我安装了electron-pug.我面临的问题如下。

如果我使用electron-forge start启动我的应用程序,我的应用程序将显示一个带有未渲染的 pug 文件的窗口(它只会显示该文件的内容( 它将记录以下内容:

Pug interceptor failed: Error: The scheme has been intercepted

但是,如果我使用electron src/index.js运行,哈巴狗模板将毫无问题地呈现。 这是我index.js文件:

const { app, BrowserWindow } = require('electron');
const pug = require('electron-pug')({pretty:true},{});
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/demo.pug`);
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
};
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow();
}
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.

这是index.pug

doctype
html
head
title Nope
body
h1 Hello
p  
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

为什么会发生这种情况的任何想法

对于遇到此问题的任何人,这就是我所做的:

Electron-Forge 支持玉模板,所以我只是将所有哈巴狗文件重命名为 jade,它就像一个魅力

最新更新