У меня есть экспресс-приложение Node.js.
layout.jade
выглядит как
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
block extraHeader
body
block content
Мой map.jade выглядит так:
extends layout
block extraHeader
link(rel='stylesheet' href='https://unpkg.com/leaflet@1.3.1/dist/leaflet.css')
script(src='https://unpkg.com/leaflet@1.3.1/dist/leaflet.js')
block content
h1= title
h2= count
#map
script.
var locations = !{JSON.stringify(jsonData)};
// Create variable to hold map element, give initial settings to map
var map = L.map('map',{ center: [0, 0], zoom: 7});
// Add OpenStreetMap tile layer to map element
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap'
}).addTo(map);
// Add JSON to map
for(var i = 0; i < locations.length; i++) {
var loc = locations[i];
L.marker([loc.lat, loc.lng]).addTo(map);
}
Я бы хотел включить дополнительный javascript в раздел в заголовке вида карты вместо встроенного скрипта, например,
<head>
... ...
<script type="text/javascript">
// DO SOMETHING
var foo = 1;
<script>
</head>
Есть ли способ сделать это?
EDIT:
Мой package.json выглядит так:
{
"name": "app_name",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bluebird": "^3.5.1",
"body-parser": "^1.18.3",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^5.0.1",
"express": "~4.16.0",
"http-errors": "~1.6.2",
"jade": "~1.11.0",
"morgan": "~1.9.0",
"nodemon": "^1.17.5",
"pg-promise": "^8.4.4"
}
}