After electron-packager packages the application, the page is blank and the index.html in the application cannot execute the introduced js script

problem description

I created the project with webpack-vue scaffolding, and after the development is complete, I need to adapt to multiple platforms, so I use electron-packager to package again. After packaging, I open the application. The js and css file paths introduced in index.html are all right, but the js file is not executed and the page is completely blank. Ask the gods how to solve this problem. The screenshot of the question is as follows:

clipboard.png

clipboard.png

the environmental background of the problems and what methods you have tried

this application can be launched on web, using webpack-dev "s server, and I have no problem launching desktop applications directly with electron. I wonder if I also need to launch a localhost server, after using electron to generate desktop applications, but I don"t know how to start such a server

.

related codes

/ / Please paste the code text below (do not replace the code with pictures)
I am using double package.json, The main contents of package.json are as follows:
Packaging script:
"packager": "electron-packager. / dist VEEClient-- platform=darwin-- arch=x64-- overwrite-- prune-- overwrite"
"main": "electron.js"
electron.js is as follows:
const {app, BrowserWindow} = require ("electron")
const url = require (" url")
const path = require ("path")

let window;
function createWindow () {

window = new BrowserWindow({
    title: "VEE Client",
    height: 600,
    width: 1000,
    minHeight: 600,
    minWidth: 800,
    minimizable: true,
    webPreferences: {
        webSecurity: false
    }
})
window.loadURL(url.format({
    pathname: path.join(__dirname, "index.html"),
    protocol: "file:",
    slashes: true
}))
window.openDevTools()
window.on("close", () => {
    window = null
})

}
app.on ("ready", createWindow)
app.on (" window-all-closed", () = > {

)
if (process.platform !== "darwin") {
    app.quit()
}

})
app.on ("activate", () = > {

)
if (window === null) {
    createWindow()
}

})

what result do you expect? What is the error message actually seen?

what I want is that the packaged application will have the same result after startup as it does after launching via Web.

Mar.25,2021

I can't see your directory structure, but according to your description, you should be using webpack's server, in the development environment, so index.html refers to the packaged js of the server address. Now in the production environment, server, cannot be started, so js cannot quote
solution: modify the address where index.html references js, change it to a relative path or the absolute path of a directory, and then change the address packaged by wepkack to the corresponding path, such as
directory structure

.
|-src
   |-index.html
   |-dist
       |- common.js// 
|-webpack.config.js

// index.html 
<script src="dist/common.js"></script>
//webpack.config.js
...
output: {
    path: path.resolve(__dirname,'src/dist'),
    filename: '[name].js',
    publicPath: '/src/dist'
},
...
Menu