use webpack instead

This commit is contained in:
Evert Prants 2017-09-15 14:22:48 +03:00
parent 93077c083f
commit d9940a0462
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
5 changed files with 597 additions and 767 deletions

1318
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -8,13 +8,11 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"css": "mkdir -p build/style && stylus -o build/style src/style/*.styl", "css": "mkdir -p build/style && stylus -o build/style src/style/*.styl",
"css:watch": "mkdir -p build/style && stylus -w -o build/style src/style/*.styl", "css:watch": "mkdir -p build/style && stylus -w -o build/style src/style/*.styl",
"js:main": "mkdir -p build/script && browserify src/script/main.js -o build/script/main.js && uglifyjs --overwrite build/script/main.js", "js": "webpack",
"js:main:watch": "mkdir -p build/script && watchify src/script/main.js -o build/script/main.js", "js:watch": "webpack -w",
"js:admin": "mkdir -p build/script && browserify src/script/admin.js -o build/script/admin.js && uglifyjs --overwrite build/script/admin.js", "watch": "concurrently --kill-others \"npm run css:watch\" \"npm run js:watch\"",
"js:admin:watch": "mkdir -p build/script && watchify src/script/admin.js -o build/script/admin.js",
"watch": "concurrently --kill-others \"npm run css:watch\" \"npm run js:main:watch\" \"npm run js:admin:watch\"",
"clean": "rm -rf build/", "clean": "rm -rf build/",
"build": "npm run clean && npm run css && npm run js:main && npm run js:admin" "build": "npm run clean && npm run css && npm run js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -59,15 +57,14 @@
"uuid": "^3.1.0" "uuid": "^3.1.0"
}, },
"devDependencies": { "devDependencies": {
"browserify": "^14.4.0",
"concurrently": "^3.5.0", "concurrently": "^3.5.0",
"eslint-plugin-import": "^2.7.0", "eslint-plugin-import": "^2.7.0",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"mustache": "^2.3.0", "mustache": "^2.3.0",
"standard": "^10.0.3", "standard": "^10.0.3",
"uglify-js": "^1.3.5", "uglifyjs-webpack-plugin": "^0.4.6",
"watch": "^1.0.2", "watch": "^1.0.2",
"watchify": "^3.9.0" "webpack": "^3.6.0"
}, },
"standard": { "standard": {
"env": { "env": {

View File

@ -1,9 +1,7 @@
import express from 'express' import express from 'express'
import config from '../../scripts/load-config'
import wrap from '../../scripts/asyncRoute' import wrap from '../../scripts/asyncRoute'
import {User} from '../api' import {User} from '../api'
import API from '../api/admin' import API from '../api/admin'
import News from '../api/news'
const router = express.Router() const router = express.Router()
const apiRouter = express.Router() const apiRouter = express.Router()

View File

@ -636,14 +636,11 @@ router.get('/docs/:name', wrap(async (req, res, next) => {
return next() return next()
} }
try { fs.readFile(doc, {encoding: 'utf8'}, (err, contents) => {
doc = fs.readFileSync(doc, {encoding: 'utf8'}) if (err) return next(err)
} catch (e) { res.header('Cache-Control', 'max-age=' + 7 * 24 * 60 * 60 * 1000) // 1 week
return next(e) res.render('document', {doc: contents})
} })
res.header('Cache-Control', 'max-age=' + 7 * 24 * 60 * 60 * 1000) // 1 week
res.render('document', {doc: doc})
})) }))
/* /*

16
webpack.config.js Normal file
View File

@ -0,0 +1,16 @@
const path = require('path')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
module.exports = {
entry: {
main: './src/script/main.js',
admin: './src/script/admin.js'
},
output: {
path: path.join(__dirname, 'build', 'script'),
filename: '[name].js'
},
plugins: [
new UglifyJSPlugin()
]
}