electron 打包的时候,没有把 video js 打包进去
时间: 2023-08-28 16:03:36 浏览: 47
如果您的 Electron 打包时没有把 video.js 打包进去,可以尝试以下几种方式:
1. 在您的 Electron 的 `main` 进程中使用 `require` 引入 video.js:
```javascript
const path = require('path');
const { app, BrowserWindow } = require('electron');
const videojs = require(path.join(__dirname, 'path/to/video.js'));
app.on('ready', () => {
const mainWindow = new BrowserWindow({ width: 800, height: 600 });
mainWindow.loadFile(path.join(__dirname, 'index.html'));
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.webContents.executeJavaScript(`window.videojs = ${JSON.stringify(videojs)};`);
});
});
```
然后,在您的渲染进程中,就可以使用 `window.videojs` 来访问 video.js 的 API 了。
2. 在您的 Electron 的打包配置文件中,使用 webpack 将 video.js 打包进去:
```javascript
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: 'production',
entry: {
main: path.join(__dirname, 'src/main.js'),
videojs: path.join(__dirname, 'path/to/video.js'),
},
output: {
filename: '[name].js',
path: path.join(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src/index.html'),
}),
new CopyWebpackPlugin([
{ from: path.join(__dirname, 'assets'), to: 'assets' },
]),
],
};
```
在这个配置中,我们将 video.js 的入口文件也作为一个入口传递给了 webpack,这样它就会被打包进去了。
希望以上的解决方案能够帮到您。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)