代码之家  ›  专栏  ›  技术社区  ›  1.21 gigawatts

如何减小电子应用程序的大小?

  •  0
  • 1.21 gigawatts  · 技术社区  · 5 年前

    我开始学习电子,我下载了入门示例项目,它的时钟大约为150MB。

    电子项目的准系统是什么?我可以删除node_modules文件夹吗?我最终需要调用一个进程,但这就是问题所在。

    0 回复  |  直到 5 年前
        1
  •  0
  •   Ajey    5 年前

    使用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 文件夹,它是您的最终捆绑输出。