express & ejs & TypeScript にBootStrapを導入する
2295 ワード
bootstrapをインストール
console.log
yarn add bootstrap
express-generater
で作られるapp.jsをTypeScript化したapp.ts
にて、下準備。
app.ts
import express, { RequestHandler } from 'express';
// 略
// ejsファイル内でbootstrapを "bootstrap/css/bootstrap.min.css" などのパスで読み込めるようにする
app.use('/bootstrap', express.static(path.join(__dirname, '../node_modules/bootstrap/dist')) as RequestHandler);
ejsファイルにてbootstrapを読み込む
views/index.ejs
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<h1 class="text-primary">Hello World</h1>
</div>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
Author And Source
この問題について(express & ejs & TypeScript にBootStrapを導入する), 我々は、より多くの情報をここで見つけました https://qiita.com/manten120/items/8876a4e4cde264d969f5著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .