javascript - Loading Bootstrap in NW.js (node-webkit) app with pure npm build -
i'm trying build simple desktop app nw.js. inspired posts including this one, wanted try pure npm approach without bower, grunt, or gulp.
so go ahead , use jquery , bootstrap libraries installed npm modules. when i'm injecting modules in app's javascript this:
global.jquery = $ = require("jquery"); var bootstrap = require("bootstrap"); i'm getting referenceerror: document not defined bootstrap. can load bootstrap through html document in old-fashioned way though:
<script type="text/javascript" src="node_modules/bootstrap/dist/js/bootstrap.js"></script> i'm asking myself if it's stupid idea load bootstrap trough require in script file? basically, don't need there. can loaded via script tag in html. best practices? i'm confused.
update. solution
having taken advice @kuf, created 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); }); triggered prestart hook:
"scripts": { "build": "node build.js", "prestart": "npm run build" } which allows me access bootstrap resources convenient paths:
<link href="vendor/css/bootstrap.css" rel="stylesheet"> <script type="text/javascript" src="vendor/js/bootstrap.js"></script>
i think error occurs because running require without window context. running include from? notice code running node-main:
window: ... not available @ time script loaded, because script executed before dom window load. (source)
even when importing js using require, still need include css files.i don't think there 'clean' or out-of-the-box solution yet. although doing work, generate weird , not natural script path.
i add build script:
"scripts": { "build": "node build.js" } in package.json copy bootstrap node_modules '/dist/' make path cleaner.
Comments
Post a Comment