Javascript 引导主题';在node.js项目中使用express routes进行s资产管理
我来自PHP背景,使用bootstrap框架有一段时间了,目前正在处理Node.js和express with routes项目。我很难理解如何在视图(index.html)中调用项目资产(js、css、图像等) 用于包括(index.php)中的文件 My index.htmlJavascript 引导主题';在node.js项目中使用express routes进行s资产管理,javascript,node.js,express,express-router,Javascript,Node.js,Express,Express Router,我来自PHP背景,使用bootstrap框架有一段时间了,目前正在处理Node.js和express with routes项目。我很难理解如何在视图(index.html)中调用项目资产(js、css、图像等) 用于包括(index.php)中的文件 My index.html <script src="../assets/jquery.min.js"></script> 上述方法不起作用,所以我遵循了这个问题 app.use(“/assets”[ static(
<script src="../assets/jquery.min.js"></script>
上述方法不起作用,所以我遵循了这个问题
app.use(“/assets”[
static(uuu dirname+/node_modules/jquery/dist/),
static(uuu dirname+'/node_modules/materialize css/dist/'),
]);
//模板中
当我将拥有资产(jquery、引导css、自定义脚本等)时,更好的方法是什么?在我的项目中,我使用以下方法将所有资产包括在视图中
var express = require("express");
var app = express();
var router = express.Router();
var path = __dirname + '/views/';
router.use(function (req,res,next) {
console.log("/" + req.method);
next();
});
app.use('/assets', [
express.static(__dirname + '/assets/'),
]);
router.get("/",function(req,res){
res.sendFile(path + "");
});
app.use("/",router);
app.use("*",function(req,res){
res.sendFile(path + "404.html");
});
然后在视图文件中调用它们(在index.html中),如
<script src="../assets/jquery.min.js"></script>
app.use('/assets', [
express.static(__dirname + '/node_modules/jquery/dist/'),
express.static(__dirname + '/node_modules/materialize-css/dist/'),
]);
<script src="/assets/jquery.min.js"></script> //in template
var express = require("express");
var app = express();
var router = express.Router();
var path = __dirname + '/views/';
router.use(function (req,res,next) {
console.log("/" + req.method);
next();
});
app.use('/assets', [
express.static(__dirname + '/assets/'),
]);
router.get("/",function(req,res){
res.sendFile(path + "");
});
app.use("/",router);
app.use("*",function(req,res){
res.sendFile(path + "404.html");
});
<script src="assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script src="assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>