forked from XerxesNoble/ProjectConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
29 lines (26 loc) · 894 Bytes
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require('fs')
const path = require('path')
const { pd } = require('pretty-data')
const html = fs.readFileSync('dist/index.html', 'utf8')
const htmlLines = html.split('\n')
const newHtml = htmlLines.map(line => {
// If line needs to be replaced
if (line.includes('<!--%')) {
const file = `dist/${line.split('%')[1]}`
const { ext, name } = path.parse(file)
switch (ext) {
case '.js':
return `<script>${fs.readFileSync(file, 'utf8')}</script>`
break
case '.css':
return `<style>${pd.cssmin(fs.readFileSync(file, 'utf8'))}</style>`
break
case '.svg':
const svg = encodeURIComponent(fs.readFileSync(file, 'utf8').split('"').join( "'"))
return `<img id="${name}" src="data:image/svg+xml;utf8,${svg}" />`
break
}
}
return line
})
fs.writeFileSync('game/index.html', pd.xmlmin(newHtml.join('')))