【问题标题】:Pug interceptor failed: Error: The scheme has been interceptedPug拦截器失败:错误:该方案已被拦截
【发布时间】:2017-08-10 11:52:30
【问题描述】:

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

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

Pug interceptor failed: Error: The scheme has been intercepted

但是,如果我使用electron src/index.js 运行,pug 模板将毫无问题地呈现。 这是我的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

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

【问题讨论】:

  • 6个月后我遇到了和你一样的问题,我没有找到解决办法;除了不使用电子锻造。 Electron 的文档推荐了 3 个构建/打包工具,其中 electron-forge 是其中之一,因此只需切换到其他两个之一。
  • @EvanThompson Electron-forge 支持翡翠,所以我将所有哈巴狗文件重命名为翡翠,一切正常

标签: pug electron electron-forge


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-03
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    相关资源
    最近更新 更多