1

I'm trying to create an 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 adds the js.files fine and recognizes 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?

Pang
  • 9,564
  • 146
  • 81
  • 122
user3242861
  • 1,839
  • 12
  • 48
  • 93

2 Answers2

1

in package.json file add like this

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

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

Mebin Joe
  • 2,172
  • 4
  • 16
  • 22
Irshad
  • 11
  • 1
0

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.

dkimot
  • 2,239
  • 4
  • 17
  • 25
  • Where I add this? in index.js file? @dkimot – user3242861 Mar 13 '18 at 19:00
  • You could add it wherever. I would recommend adding it close to where assets would be used. If you have a server.js file whose purpose is to create a server that sends static assets, like your CSS and images, you could add the lines `path.join(__dirname, '../path/to/asset.css')` above the line that creates a static route. That way you don't need to read as much code to see where that's being required. Definitely, add comments as this is not really convention so people know why you are randomly joining a path. – dkimot Mar 13 '18 at 19:03
  • Ok, I did it for .css and work fine. And for images folder inside public folder? I do this path.join(__dirname, '/public/images'); and don't work @dkimot – user3242861 Mar 13 '18 at 19:16
  • Try the same thing with a backslash at the end (`path.join(__dirname, '/public/images/');` – dkimot Mar 13 '18 at 19:17
  • Okay, try adding the images as an asset to package.json. If that doesn't work, as an experiment can you try specifying an image file extension in the package.json to see what happens? Something like `"assets": "public/images/*.png"` just to see if that helps. Then we can work on getting all file types. – dkimot Mar 13 '18 at 21:52