2017-09-24 313 views
0

我一直在研究一個涉及Electron,VueJS的新項目,並且我正在使用Webpack來處理HMR功能......我的問題是熱模塊替換的東西由於某種原因不工作。VueJS,Electron和Webpack(Hot Reload)的問題

我已經得到了以下配置:

webpack.config.js

var path = require('path'); 
var webpack = require('webpack'); 

module.exports = { 
    entry: './app/index.js', 
    output: { 
    path: path.resolve(__dirname, './dist'), 
    // publicPath: '/dist/', 
    filename: 'build.js', 
    }, 
    resolve: { 
    alias: { 
     'vue': 'vue/dist/vue.common.js', 
    }, 
    }, 
    module: { 
    loaders: [ 
     { 
     test: /\.vue$/, 
     loader: 'vue-loader', 
     }, 
     { 
     test: /\.js$/, 
     loader: 'babel-loader', 
     exclude: /node_modules/, 
     }, 
     { 
     test: /\.css/, 
     loader: 'style-loader!css-loader', 
     }, 
    ], 
    }, 
    plugins: [ 
    new webpack.ExternalsPlugin('commonjs', [ 
     'electron', 
    ]), 
    new webpack.HotModuleReplacementPlugin(), 
    new webpack.LoaderOptionsPlugin({ 
     babel: { 
     'presets': ['env'], 
     'plugins': ['transform-runtime'], 
     }, 
    }), 
    ], 
}; 

的index.html(掛載點Vue公司)

<!DOCTYPE html> 
<html> 

    <head> 
    <title>Hermes - Empyrion Environment Editor!</title> 
    <style> 
     body { 
     background-color: #222222; 
     margin: 0; 
     padding: 0; 
     } 
    </style> 
    </head> 

    <body> 
    <div id="root"></div> 
    <script src="http://localhost:8080/webpack-dev-server.js"></script> 
    </body> 

</html> 

index.js(電子初始化等)

const electron = require('electron'); 
const { app, BrowserWindow } = electron; 

// Main Window Handle 
let mainWindow; 

app.on('ready',() => { 
    let mainWindow = null; 
    const loadingWindow = new BrowserWindow({ 
    width: 325, 
    height: 425, 
    frame: false, 
    show: false, 
    }); 
    loadingWindow.once('show',() => { 
    mainWindow = new BrowserWindow({ 
     width: 1024, 
     height: 768, 
     minWidth: 1024, 
     minHeight: 768, 
     show: false, 
    }); 
    mainWindow.webContents.once('dom-ready',() => { 
     mainWindow.show(); 
     loadingWindow.hide(); 
     loadingWindow.close(); 
    }); 
    mainWindow.loadURL(`file://${__dirname}/index.html`); 
    mainWindow.on('closed',() => { 
     mainWindow = null; 
    }); 
    }); 
    loadingWindow.loadURL(`file://${__dirname}/loading.html`); 
    loadingWindow.show(); 
}); 

app.on('window-all-closed',() => { 
    if (process.platform !== 'darwin') { 
    app.quit(); 
    } 
}); 

app.on('activate',() => { 
    if (mainWindow === null) { 
    mainWindow = new BrowserWindow({ 
     width: 1024, 
     height: 768, 
     minWidth: 1024, 
     minHeight: 768, 
     show: true, 
    }); 
    mainWindow.webContents.once('dom-ready',() => { 
     mainWindow.show(); 
    }); 
    mainWindow.loadURL(`file://${__dirname}/index.html`); 
    } 
}); 

我不知道我在做什麼錯。如果我在index.html中使用http://localhost:8080/dist/build.js,該應用程序在Electron中工作,但沒有Hot Reload功能(需要刷新頁面)......但是如果我使用http://localhost:8080/webpack-dev-server.js(我認爲這是我應該使用的),則不會收到任何內容在應用程序加載時,只是一個空白窗口。

當我運行的WebPack開發服務器(webpack-dev-server --hot --inline),我得到的JS控制檯下面的輸出,但應用程序不會在瀏覽器中加載(測試:

[WDS] Hot Module Replacement enabled. 

它充當如果HMR確實是工作,但應用程序的其餘部分加載失敗。如果我前往http://localhost:8080/loading.html雖然,工作正常。我只能假設我沒有引用與<script>標籤正確的文件中index.html

任何援助將不勝感激。我唯一能想到的就是mayb e它在電子初始化中不喜歡loadURL()file://路徑。提前致謝!

回答