简体   繁体   中英

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.

So, I install pkg with npm install -g pkg , in package.json I add this:

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

It add the js.files fine and recognize views, except css file.

My project structure is that:

  • public
    • css
      • app.css
    • js
      • app.js
    • images
  • views

In console I ran the command pkg . and it generates linux, macos and win executables.

How can I add my css file and image folder too?

One solution is to have pkg detect assets in the source code rather than using a config object at the package.json level.

This is documented here . Basically, if you add the line path.join(__dirname, '../path/to/asset.css'); to your source code pkg should automatically add it to the executable.

in package.json file add like this

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

put all you images, js, css etc into Public folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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