【问题标题】:How to reduce the size of an Electron app?如何减小 Electron 应用程序的大小?
【发布时间】:2019-05-20 12:57:09
【问题描述】:

我正在开始使用 Electron,我下载了入门示例项目,它的时钟大约为 150MB。

电子项目的准系统是什么?我可以删除 node_modules 文件夹吗?我最终将需要调用一个进程,但仅此而已。

【问题讨论】:

    标签: electron electron-packager


    【解决方案1】:

    使用 webpack 并仅发布应用所需的依赖项。 另外,使用copy-webpack-plugin复制你需要的文件,这些文件不是通过webpack捆绑的。

    不要运送整个 node_modules 文件夹。

    示例 webpack 配置 -

        const path = require('path');
        var CopyWebpackPlugin = require('copy-webpack-plugin');
    
        module.exports = {
            entry: {
                main: './main.ts',
                renderer: './src/renderer.js',
            },
            devtool: 'inline-source-map',
            output: {
                filename: "[name].js",
                path: path.resolve(__dirname, 'public')
            },
            resolve: {
                extensions: [".tsx", ".ts", ".js"]
            },
            module: {
                rules: [
                    {
                        test: /\.js$/,
                        exclude: /(node_modules|bower_components)/,
                        use: {
                            loader: 'babel-loader',
                            options: {
                                presets: ["es2015", "react"]
                            }
                        }
                    },
                    {
                        test: /\.tsx?$/,
                        use: 'ts-loader',
                        exclude: /node_modules/
                    }
                ]
            },
            target: "electron-main",
            bail: true,
            node: {
                __dirname: false,
                __filename: false
            },
            plugins: [
                new CopyWebpackPlugin([
                    { from: './index.html' }
                ])
            ]
        };
    

    所以上面创建了一个public 文件夹,这是您的最终捆绑输出。

    【讨论】:

      猜你喜欢
      • 2021-01-23
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2021-04-30
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多