4

When I work locally I want to share code among two or more (nwjs and other kinds of) projects. Folder structure:
-project 1
-project 2
-shared code

When releasing the apps I build the external files into a file inside each project app.

But I cannot access files outside the node-webkit/nwjs app folder.

I tried things like:
Setting "chromium-args": "--allow-file-access-from-files" in the manifest file but I think this is default now.
Using file:/// and chromium-extension:/// prepending the relative paths but I think this is only for absolute paths?
Load files dynamically and using path.relative( process.cwd(), "../shared_code/scripts/controllers/searchController.js" );

The user of the app will be able to put it anywhere on his computer.

Is it possible to load js and css files and images from outside the nwjs project folder locally?

nwjs sdk version 0.19.5

jerry
  • 145
  • 3
  • 13
  • There's a logical fallacy in my question: I only need the files outside my app folder locally during development, so I can actually use absolute paths. What worked for me was the file:/// prepend, the chromium-extension:/// doesn't. But I think the question still could be valid for people who want to point to relative paths outside an nwjs app folder. – jerry Feb 26 '17 at 09:35

2 Answers2

0

I had a similar problem trying to load images outside of the NW.js application. I found that this fixed my issues. Try adding this to your JSON manifest file. This worked for me...

"chromium-args": "--allow-file-access-from-files --allow-file-access --user-data-dir"

Just so you know, I had originally tried this...

"chromium-args": "--allow-file-access-from-files --allow-file-access --user-data-dir --mixed-context"

But it stopped jquery loading. You can then access files with file:/// and use absolute paths anywhere on the machine.

I hope that helps.

1j01
  • 3,714
  • 2
  • 29
  • 30
0

For sharing code, when the code is (or can be) a node module, it's very helpful to be able to npm link it into your project. (It works the same with NW.js apps as for Node.js:)

cd shared-code
npm link

cd ../project-1
npm link shared-code

cd ../project-2
npm link shared-code
1j01
  • 3,714
  • 2
  • 29
  • 30