mirror of
https://github.com/kognise/water.css.git
synced 2025-12-08 07:45:02 +01:00
Removed old dev server and updated build/dev tasks
This commit is contained in:
parent
a4f4eb370a
commit
b500878f5a
2 changed files with 2 additions and 77 deletions
75
dev.js
75
dev.js
|
|
@ -1,75 +0,0 @@
|
||||||
const express = require('express')
|
|
||||||
const app = express()
|
|
||||||
const http = require('http').Server(app)
|
|
||||||
const io = require('socket.io')(http)
|
|
||||||
const fs = require('fs-extra')
|
|
||||||
const chokidar = require('chokidar')
|
|
||||||
const sass = require('node-sass')
|
|
||||||
|
|
||||||
const script = `
|
|
||||||
const socket = io()
|
|
||||||
socket.on('reload', () => location.reload())
|
|
||||||
`
|
|
||||||
|
|
||||||
app.get('/', async (req, res) => {
|
|
||||||
console.log('> Serving index')
|
|
||||||
const html = await fs.readFile('index.html')
|
|
||||||
const injected = html.toString().replace('</body>', `<script src='/socket.io/socket.io.js'></script><script>${script}</script></body>`)
|
|
||||||
res.send(injected)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get('/script.js', async (req, res) => {
|
|
||||||
console.log('> Serving script')
|
|
||||||
const script = await fs.readFile('script.js')
|
|
||||||
res.contentType('javascript')
|
|
||||||
res.send(script)
|
|
||||||
})
|
|
||||||
|
|
||||||
app.use('/dist', (req, res, next) => {
|
|
||||||
console.log('> Serving a stylesheet')
|
|
||||||
next()
|
|
||||||
}, express.static('dist'))
|
|
||||||
|
|
||||||
function reload() {
|
|
||||||
console.log('> Reloading')
|
|
||||||
io.emit('reload')
|
|
||||||
}
|
|
||||||
|
|
||||||
chokidar.watch('index.html', { ignoreInitial: true }).on('all', () => {
|
|
||||||
console.log('> Index changed')
|
|
||||||
reload()
|
|
||||||
})
|
|
||||||
|
|
||||||
chokidar.watch('script.js', { ignoreInitial: true }).on('all', () => {
|
|
||||||
console.log('> Script changed')
|
|
||||||
reload()
|
|
||||||
})
|
|
||||||
|
|
||||||
function buildSass(file) {
|
|
||||||
sass.render({ file, outputStyle: 'compressed' }, async (errors, result) => {
|
|
||||||
if (errors) {
|
|
||||||
console.log('> Sass errors!')
|
|
||||||
console.log(errors)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const outFile = file.replace('src', 'dist').replace('.scss', '.css')
|
|
||||||
await fs.outputFile(outFile, result.css)
|
|
||||||
reload()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
chokidar.watch('src/*.scss', { ignoreInitial: true }).on('all', (event, file) => {
|
|
||||||
console.log('> Stylesheet changed')
|
|
||||||
buildSass(file)
|
|
||||||
})
|
|
||||||
|
|
||||||
chokidar.watch('src/parts/*.scss', { ignoreInitial: true }).on('all', async () => {
|
|
||||||
console.log('> Stylesheet part changed')
|
|
||||||
const src = await fs.readdir('src')
|
|
||||||
const files = src.filter(file => file !== 'parts').map(file => `src/${file}`)
|
|
||||||
for (let file of files) {
|
|
||||||
buildSass(file)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
http.listen(3000, () => console.log('> Ready at http://localhost:3000/'))
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
"description": "A just-add-css collection of styles to make simple websites just a little nicer.",
|
"description": "A just-add-css collection of styles to make simple websites just a little nicer.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node-sass src/ --output dist/ --output-style compressed",
|
"build": "gulp style",
|
||||||
"dev": "node dev.js"
|
"dev": "gulp watch"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue