I am trying to create a simple desktop application with NW.js. Inspired by some posts, including this one , I wanted to try a clean npm approach without any bower , grunt or gulp .
So, I am using jquery and bootstrap libraries installed as npm . When I insert modules into my javascript application as follows:
global.jQuery = $ = require("jquery"); var bootstrap = require("bootstrap");
I get ReferenceError: document is not defined from bootstrap . I can load bootstrap through the html document as before:
<script type="text/javascript" src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
I ask myself if the stupid idea is to load the require boot tray into a script file? In principle, I do not need him. It can be downloaded using the script tag in html. What are the best practices? I am embarrassed.
Refresh. Decision
After getting advice from @Kuf, I created a build.js script
var copyfiles = require('copyfiles'); copyfiles(["node_modules/bootstrap/dist/js/bootstrap.js", "vendor/js"], true, function (err) { if (err) return console.error(err); }); copyfiles(["node_modules/bootstrap/dist/css/bootstrap.css", "vendor/css"], true, function (err) { if (err) return console.error(err); });
called prestart hook:
"scripts": { "build": "node build.js", "prestart": "npm run build" }
which allows me access to bootstrap resources using convenient paths:
<link href="vendor/css/bootstrap.css" rel="stylesheet"> <script type="text/javascript" src="vendor/js/bootstrap.js"></script>