Skip to content

Commit 06354e9

Browse files
Added builder and separated static directory
1 parent 3fc1fb8 commit 06354e9

38 files changed

+607
-4
lines changed

index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1+
const fs = require('fs');
12
const path = require('path');
23

34
const express = require('express');
45
const pug = require('pug');
6+
const sass = require('sass');
57

68
const app = express();
79
const port = 3000;
810

9-
app.use('/', express.static(path.join(__dirname, 'src/static')))
11+
const SRC_PATH = path.join(__dirname, 'src');
12+
const STATIC_PATH = path.join(__dirname, 'static');
13+
const CSS_PATH = path.join(STATIC_PATH, 'css/style.css');
14+
const HTML_PATH = path.join(STATIC_PATH, 'index.html');
1015

11-
app.get('/', (req, res) => {
12-
res.send(pug.renderFile('./src/index.pug'));
16+
app.use('/', express.static(path.join(STATIC_PATH)))
17+
18+
app.get('/', async (_, res) => {
19+
// Build Pug file
20+
console.log('Building Pug file...');
21+
22+
const compiledFunction = pug.compileFile(path.join(SRC_PATH, 'index.pug'));
23+
24+
fs.writeFileSync(HTML_PATH, compiledFunction());
25+
26+
console.log('Build successful!');
27+
28+
// Build SCSS file
29+
console.log('Building SCSS file...');
30+
31+
const result = await sass.compileAsync(path.join(SRC_PATH, 'style.scss'));
32+
33+
fs.writeFileSync(CSS_PATH, result.css);
34+
35+
console.log('Build successful!');
36+
37+
// Render HTML file
38+
res.send(pug.renderFile(HTML_PATH));
1339
});
1440

1541
app.listen(port, () => {

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
22
"name": "css-room-escape",
33
"private": true,
4-
"version": "2.0.0",
4+
"version": "2.1.0",
55
"repository": "https://github.com/takaneichinose/profile.git",
66
"author": "Takane Ichinose <[email protected]>",
77
"license": "MIT",
88
"dependencies": {
99
"express": "^4.18.2",
1010
"pug": "^3.0.2"
11+
},
12+
"devDependencies": {
13+
"sass": "^1.68.0"
1114
}
1215
}
File renamed without changes.

0 commit comments

Comments
 (0)