Electron 构建器未将我的 dist/node_modules 目录复制到正确的位置

发布于 2025-01-09 07:03:42 字数 1304 浏览 1 评论 0原文

我有一个节点应用程序,我已经使用 Electron 启动了该应用程序。现在,我想将其与电子构建器打包,但我正在处理如此奇怪的行为。通常,当我构建应用程序时,会生成一个 dist 文件夹,其中包含所有已转译的 javascript 文件以及 package.json。然后,我必须再次运行 npm i --product 来设置我的生产依赖项。所以我希望 Electron-builder 做的是在安装完所有内容后准确复制 dist 目录:

electron-builder build --linux AppImage

这是我的 package.json 相关配置:

  "main": "dist/app.js",
  "build": {
    "appId": "my.app",
    "files": [
      "dist/**/*"
    ]
  },

我想通过此配置,我告诉它复制 dist 目录并它的内容。 AppImage 文件已构建,如果我解压缩它,我可以看到内部创建了一个 resources 目录,其中包含一个 app.asar 文件。如果我提取 asar 内容,我可以看到 node_modules 被放置在与 dist 相同的级别,而不是在其中!所以我有:

  AppImage
  -- resources
  ---- app.asar
  ------ node_modules
  ------ dist (everything except node_modules)

当我启动应用程序时,它显然抱怨找不到 node_modules文档说有一些默认文件模式可以优先于用户定义的文件模式...

我也尝试过:

"files": {
  "from": "dist",
  "to": "dist",
  "filter": ["**/*"]
}

并且似乎无法找到 package.json 文件。

几年前有人问过这个类似的问题,没有答案。有什么帮助吗?

I've got one node application which I'm already launching with Electron. Now, I want to package it with electron-builder, but I'm dealing with such an strange behaviour. Usually, when I build my application, a dist folder gets generated, containing all the transpiled javascript files and also the package.json. Then, I have to run npm i --production again there to set up my production dependencies. So what I want electron-builder to do is to copy exactly the dist directory as it is once everything is installed:

electron-builder build --linux AppImage

This is my package.json related config:

  "main": "dist/app.js",
  "build": {
    "appId": "my.app",
    "files": [
      "dist/**/*"
    ]
  },

I guess that with this configuration I'm telling it to copy the dist directory and its contents. The AppImage file gets built and if I unzip it, I can see a resources dir gets created inside, containing one app.asar file. If I extract the asar content, I can see node_modules gets placed at the same level than dist, and not inside of it!! So I have:

  AppImage
  -- resources
  ---- app.asar
  ------ node_modules
  ------ dist (everything except node_modules)

When I launch the application it obviously complains of not finding the node_modules. The docs say there's some default files pattern which can take precedence of what user has defined...

I also have tried:

"files": {
  "from": "dist",
  "to": "dist",
  "filter": ["**/*"]
}

And seems not being able to find the package.json file.

Somebody asked this similar question years ago, with no answer. Any help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

治碍 2025-01-16 07:03:42

最后我找到了方法,我必须使用我在 中找到的属性来调整配置docsincludeSubNodeModules,默认为false,并且似乎在输出中包含node_modules子文件夹。另外,我必须明确省略根 node_modules 文件夹,因为我不希望它出现在输出中。

  "build": {
    "appId": "myApplication",
    "files": [
      "dist/**/*",
      "!node_modules"
    ],
    "includeSubNodeModules": true
  },

Finally I found the way to do it, I had to tweak the configuration with a property that I found in the docs: includeSubNodeModules, which defaults to false and seems to include the node_modules subfolders in the output. Also I had to explicitly omit the root node_modules folder since I don't want it in the output.

  "build": {
    "appId": "myApplication",
    "files": [
      "dist/**/*",
      "!node_modules"
    ],
    "includeSubNodeModules": true
  },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文