简体   繁体   English

Node js - 如何使用 pkg 创建可执行文件

[英]Node js - How to create an executable with pkg

I'm trying to create a executable in my node.js project with pkg and I can create this but without css files.我正在尝试使用pkg在我的 node.js 项目中创建一个executable ,我可以创建它但没有 css 文件。

So, I install pkg with npm install -g pkg , in package.json I add this:因此,我使用npm install -g pkg pkgpackage.json中添加:

"pkg": {
    "scripts": "public/js/*.js",
    "assets": "public/css/*.css",
    "assets": "views/**/*"
  },

It add the js.files fine and recognize views, except css file.它可以很好地添加 js.files 并识别视图,但 css 文件除外。

My project structure is that:我的项目结构是:

  • public上市
    • css css
      • app.css应用程序.css
    • js js
      • app.js应用程序.js
    • images图片
  • views意见

In console I ran the command pkg .在控制台中,我运行了命令pkg . and it generates linux, macos and win executables.它会生成 linux、macos 和 win 可执行文件。

How can I add my css file and image folder too?如何也添加我的 css 文件和图像文件夹?

One solution is to have pkg detect assets in the source code rather than using a config object at the package.json level.一种解决方案是让pkg检测源代码中的资产,而不是在package.json级别使用配置对象。

This is documented here .在此处记录。 Basically, if you add the line path.join(__dirname, '../path/to/asset.css');基本上,如果您添加行path.join(__dirname, '../path/to/asset.css'); to your source code pkg should automatically add it to the executable.到您的源代码pkg应自动将其添加到可执行文件中。

in package.json file add like this在 package.json 文件中添加这样

 "pkg": {    
     "assets": [
         "views/*",
         "Public/**/*"    
      ],
  ...
  }

put all you images, js, css etc into Public folder将所有图像、js、css 等放入公共文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM