git import default tip
authoragaric <agaric@protonmail.com>
Mon, 08 Mar 2021 19:16:18 +0000
changeset 0 4ebce088706c
git import
.babelrc
.hgignore
LICENSE
README.org
component/App.js
component/Foot.js
component/Timer.js
index.dev.html
index.html
index.js
index.prod.html
package.json
pub/css/style.css
util/index.js
webpack.config.js
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.babelrc	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,7 @@
+{
+  "plugins": [
+    "transform-class-properties",
+    "transform-decorators-legacy"
+  ],
+  "presets": ["env", "react"]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,6 @@
+\.git/
+\.gitignore
+.*\.log$
+node_modules/
+^pub/(?!css)
+^package-lock.json$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LICENSE	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,7 @@
+(c) 2018-2020, agaric <agaric@protonmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.org	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,44 @@
+* woke
+
+*woke* is a countdown alarm clock for the browser. For those (rare) occasions where the phone is less handy, or you want to see the timer on a bigger screen, or you need the functionality with just a browser and an internet connection.
+
+Status: beta
+
+Backstory: Lost my phone and gotta wake up tomorrow.
+
+*** use it!
+
+[[https://b.agaric.net/dev/woke/]]
+
+*** run it locally
+
+#+BEGIN_SRC sh
+cd woke
+mkdir -p pub/sound
+cp /YOUR/ALARM/SOUND/FILE.mp3 pub/sound/alarm.mp3
+cp index.dev.html index.html
+npm install
+npm run dev
+# start a webserver like python -m http.server 8000
+# visit localhost:8000 in a js-enabled browser
+#+END_SRC
+
+*** functionality
+
+- h, m, s configuration
+- see countdown
+- audio + visual beep
+- keyboard control
+
+**** todo
+
+- sound selection
+- sound preview
+- theme selection
+
+*** includes
+
+- [[http://momentjs.com/][moment]]
+- [[https://reactjs.org/][react]], [[https://babeljs.io/][babel]], [[https://webpack.github.io/][webpack]]
+- [[https://github.com/thangngoc89/react-howler][react-howler]]
+- [[https://github.com/glortho/react-keydown][react-keydown]]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/component/App.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,12 @@
+import React from "react"
+import Foot from "./Foot"
+import Timer from "./Timer"
+
+const App = () => (
+  <div className="app">
+    <Timer />
+    <Foot />
+  </div>
+)
+
+export default App
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/component/Foot.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,21 @@
+import React from "react"
+import {prefix} from "../util"
+
+const Foot = () => (
+  <div className="foot">
+    <div className="left">
+      <span className="bold">for effective use:</span> confirm power supply (if mobile) & browser audio volume
+      <br />
+      <span className="bold">keys:</span> (<span className="bolder">Shift</span>)<span className="bolder">Tab</span> cycle focus, <span className="bolder">Up</span>/<span className="bolder">Down</span> +1/-1, <span className="bolder">Enter</span> start/pause, <span className="bolder">Space</span> pause, <span className="bolder">Escape</span> stop
+    </div>
+    <div className="right">
+      <a href="https://github.com/blobject/woke">
+        <img src={prefix("/pub/img/github.png")} />
+      </a>
+      {" "}brought to you by
+      {" "}<a href="https://b.agaric.net">agaric</a>
+    </div>
+  </div>
+)
+
+export default Foot
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/component/Timer.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,261 @@
+import Moment from "moment"
+import React, {Component} from "react"
+import Howl from "react-howler"
+import Keydown from "react-keydown"
+import {prefix} from "../util"
+
+// global enums + constants
+const D = Object.freeze({up: {}, down: {}})
+const S = Object.freeze({beeping: {}, paused: {}, running: {}})
+const V = Object.freeze({bip: {}, bop: {}})
+const SOUND = prefix("/pub/sound/alarm.mp3")
+const TICK = 1000 // msec
+
+// helpers
+const basename = (s) => new String(s).substring(s.lastIndexOf("/") + 1)
+const partname = (e) => e.parentNode.className
+const bottom = (n, s) => {
+  const d = s === "hour" ? 3600 : s === "minute" ? 60 : 1
+  return Math.floor(n / 1000 / d) === 0
+}
+const clone = (o) => JSON.parse(JSON.stringify(o))
+const pad = (n) => ("00" + n).slice(-2)
+const pads = (o) => ({
+  hour: pad(o.hour),
+  minute: pad(o.minute),
+  second: pad(o.second)
+})
+const parts = (n) => {
+  const m = Moment.duration(n)
+  return {hour: m.hours(), minute: m.minutes(), second: m.seconds()}
+}
+// o.* types are ambiguous, can be "01" or 1
+const whole = (o) => ((Number(o.hour) * 60 * 60)
+                    + (Number(o.minute) * 60)
+                    + Number(o.second)) * 1000
+
+// subcomponents
+
+const Part = (v, c, k, d) => (
+  <input type="text" value={v} onChange={c} onKeyDown={k} disabled={d} />
+)
+
+// show can be null, so explicitly check for false
+const Arrow = (dir, click, hid, show) => (
+  <div className={dir + (hid ? " hid" : show === false ? " dim" : "")}
+       onClick={hid || show === false ? null : click}>
+  </div>
+)
+
+@Keydown
+class Timer extends Component {
+  constructor(props) {
+    super(props)
+    this.defaultState = {
+      status: null,
+      timer: null,
+      visual: null,
+      count: 0, // the view-determining central value, in ms
+      hour: "00",
+      minute: "00",
+      second: "00"
+    }
+    this.state = clone(this.defaultState)
+    this._onArrowClick = this._onArrowClick.bind(this)
+    this._onButtonClick = this._onButtonClick.bind(this)
+    this._onInputChange = this._onInputChange.bind(this)
+    this._onKeydown = this._onKeydown.bind(this)
+  }
+
+  componentWillReceiveProps(nextProps) {
+    const {keydown: {event}} = nextProps;
+    if (event) this._onKeydown(event)
+  }
+
+  componentWillUnmount() {
+    this._stop() // probably unused
+  }
+
+  _onButtonClick = () => {
+    const {status} = this.state
+    if      (!status)              this._start()
+    else if (status === S.running) this._pause()
+    else if (status === S.beeping) this._stop()
+    else if (status === S.paused)  this._start()
+    else console.log("unknown status")
+  }
+
+  _onInputChange = (event) => {
+    const target = event.target
+    const {hour, minute, second} = this.state
+    const time = {hour, minute, second}
+    time[partname(target)] = target.value
+    this._updateTime(whole(time))
+  }
+
+  _onKeydown(event) {
+    if (!(event.type === "keydown")) return
+    const key = event.key;
+    const target = event.target;
+    const isButton = target.nodeName === "BUTTON"
+    const isInput = target.nodeName === "INPUT"
+
+    const {status, count} = this.state
+    const stopped = !status
+    const beeping = status === S.beeping
+    const paused  = status === S.paused
+    const running = status === S.running
+    const ready   = stopped && count > 0
+
+    // concerns <body>, <button>, <input>
+    if (key === "Enter" || key === " ") {
+      // pressing "Enter" or "space" on a button overlaps with _onButtonClick,
+      // let latter take precedence
+      if (isButton) return
+      if      (running) this._pause()
+      else if (paused)  this._start()
+      else if (ready && key === "Enter") this._start()
+
+    } else if (key === "Escape") {
+      if (paused || beeping || ready) this._stop()
+    }
+
+    // concerns <input> only
+    if (isInput) {
+      const part = partname(target)
+      const cls = target.className
+      const val = Number(target.value)
+      const inputAllowed = ["Shift", "ArrowLeft", "ArrowRight",
+                            "Tab", "Backspace", "Delete"]
+
+      if (key === "ArrowUp") {
+        event.preventDefault()
+        this._inc(D.up, part, val)
+      } else if (key === "ArrowDown") {
+        event.preventDefault()
+        if (count > 0 && !bottom(count, part))
+          this._inc(D.down, part, val)
+
+      } else if (inputAllowed.includes(key)) {
+        return
+
+      } else if (isNaN(key)) { // now, only accept digits
+        event.preventDefault()
+      }
+    }
+  }
+
+  _onArrowClick = (event) => {
+    const target = event.target
+    const dir = target.className === "up" ? D.up : D.down
+    const part = partname(target)
+    this._inc(dir, part, Number(this.state[part]))
+  }
+
+  _inc = (dir, part, val) => {
+    const {hour, minute, second} = this.state
+    const time = {hour, minute, second}
+    time[part] = val + (dir === D.up ? 1 : -1)
+    this._updateTime(whole(time))
+  }
+
+  _start = () => {
+    this.setState({status: S.running, timer: setInterval(this._tick, TICK)})
+  }
+
+  _beep = () => {
+    this.setState({status: S.beeping, count: 0})
+  }
+
+  _pause = () => {
+    clearInterval(this.state.timer)
+    this.setState({status: S.paused})
+  }
+
+  // for both cancelling and shutting-up
+  _stop = () => {
+    clearInterval(this.state.timer)
+    this.setState(clone(this.defaultState))
+  }
+
+  _tick = () => {
+    const {count, visual} = this.state
+    if      (visual === V.bip) this.setState({visual: V.bop})
+    else if (visual === V.bop) this.setState({visual: V.bip})
+    else {
+      const next = count - TICK
+      if (next <= 0) {
+        this.setState({visual: V.bip})
+        this._beep()
+      }
+      this._updateTime(next)
+    }
+  }
+
+  _updateTime = (count) => {
+    const time = pads(parts(count))
+    const {hour, minute, second} = time
+    this.setState({count, hour, minute, second})
+  }
+
+  render() {
+    const {status, visual, timer, count, hour, minute, second} = this.state
+    const ac = this._onArrowClick
+    const bc = this._onButtonClick
+    const ic = this._onInputChange
+    const kd = this._onKeydown
+    const stopped = !status
+    const beeping = status === S.beeping
+    const paused  = status === S.paused
+    const running = status === S.running
+    const unready = stopped && count <= 0 // for disabling button
+    const blocked = beeping || running    // for disabling inputs
+    const bip = visual === V.bip
+    const bop = visual === V.bop
+    const play = beeping ? true : false
+    const text = beeping ? "shut up"
+               : paused  ? "resume"
+               : running ? "pause"
+               : "start"
+
+    return (
+      <div className={"timer" + (bip ? " beep bip" : bop ? " beep bop" : "")}>
+        <Howl src={SOUND} loop={true} playing={play} preload={true} />
+        <div className="info">
+          <div className="sound">
+            <span className="label">sound:</span> {basename(SOUND)}
+          </div>
+          <div className="count">{count <= 0 ? 0 : count / 1000}</div>
+        </div>
+        <div className={"time" + (running ? " running" : "")}>
+          <div className="hour">
+            {Arrow("up", ac, blocked)}
+            {Part(hour, ic, kd, blocked)}
+            {Arrow("down", ac, blocked, !bottom(count, "hour"))}
+          </div>:
+          <div className="minute">
+            {Arrow("up", ac, blocked)}
+            {Part(minute, ic, kd, blocked)}
+            {Arrow("down", ac, blocked, !bottom(count, "minute"))}
+          </div>:
+          <div className="second">
+            {Arrow("up", ac, blocked)}
+            {Part(second, ic, kd, blocked)}
+            {Arrow("down", ac, blocked, count > 0)}
+          </div>
+        </div>
+        <button className={"button" + (unready ? " disabled" : "")}
+                onClick={unready ? null : bc}>
+          {text}
+        </button>
+        {paused && (
+          <button className="stop-button" onClick={this._stop}>
+            stop
+          </button>
+        )}
+      </div>
+    )
+  }
+}
+
+export default Timer
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.dev.html	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,13 @@
+<html>
+  <head>
+    <title>woke</title>
+    <meta content="width=device-width, initial-scale=1" name="viewport">
+    <link href="/favicon.ico" rel="icon">
+    <link href="/pub/css/style.css" rel="stylesheet" type="text/css">
+    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:500,700" rel="stylesheet">
+    <div id="root"></div>
+    <script src="/pub/dist/woke.js"></script>
+  </head>
+  <body>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.html	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,13 @@
+<html>
+  <head>
+    <title>woke</title>
+    <meta content="width=device-width, initial-scale=1" name="viewport">
+    <link href="/dev/woke/favicon.ico" rel="icon">
+    <link href="/dev/woke/pub/css/style.css" rel="stylesheet" type="text/css">
+    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:500,700" rel="stylesheet">
+    <div id="root"></div>
+    <script src="/dev/woke/pub/dist/woke.js"></script>
+  </head>
+  <body>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,5 @@
+import React from 'react'
+import {render} from 'react-dom'
+import App from './component/App'
+
+render((<App />), document.getElementById('root'))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/index.prod.html	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,13 @@
+<html>
+  <head>
+    <title>woke</title>
+    <meta content="width=device-width, initial-scale=1" name="viewport">
+    <link href="/dev/woke/favicon.ico" rel="icon">
+    <link href="/dev/woke/pub/css/style.css" rel="stylesheet" type="text/css">
+    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:500,700" rel="stylesheet">
+    <div id="root"></div>
+    <script src="/dev/woke/pub/dist/woke.js"></script>
+  </head>
+  <body>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.json	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,41 @@
+{
+  "name": "woke",
+  "version": "0.0.1",
+  "description": "countdown alarm clock",
+  "license": "MIT",
+  "main": "index.js",
+  "scripts": {
+    "dev": "webpack -d --watch",
+    "prod": "webpack --env.prod --optimize-minimize --progress"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/blobject/woke.git"
+  },
+  "bugs": {
+    "url": "https://github.com/blobject/woke/issues"
+  },
+  "author": {
+    "name": "agaric",
+    "email": "agaric@protonmail.com",
+    "url": "https://b.agaric.net"
+  },
+  "homepage": "https://github.com/blobject/woke",
+  "dependencies": {
+    "moment": "^2.20.1",
+    "react": "^16.2.0",
+    "react-dom": "^16.2.0",
+    "react-howler": "^3.7.1",
+    "react-keydown": "^1.9.6"
+  },
+  "devDependencies": {
+    "babel-core": "^6.26.0",
+    "babel-loader": "^7.1.2",
+    "babel-plugin-transform-class-properties": "^6.24.1",
+    "babel-plugin-transform-decorators-legacy": "^1.3.4",
+    "babel-polyfill": "^6.26.0",
+    "babel-preset-env": "^1.6.1",
+    "babel-preset-react": "^6.24.1",
+    "webpack": "^3.11.0"
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pub/css/style.css	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,284 @@
+body, button, input {
+  font-family: 'Roboto Mono', monospace;
+  font-weight: 700;
+}
+
+body {
+  margin: 0;
+  padding: 0;
+}
+
+a {
+  color: #3f51b5;
+  text-decoration: none;
+}
+
+.app {
+  display: flex;
+  flex-direction: column;
+  height: 100%;
+  width: 100%;
+}
+
+.foot {
+  display: flex;
+  flex-wrap: wrap;
+  justify-content: space-between;
+  align-items: flex-end;
+  position: absolute;
+  bottom: 0;
+  left: 0;
+  right: 0;
+}
+
+.foot .left,
+.foot .right {
+  background: rgb(255, 255, 255) transparent;
+  background: rgba(255, 255, 255, .2);
+  padding: 5px 10px;
+  border-radius: 4px;
+}
+
+.foot .left {
+  font-size: 13px;
+  color: #b0b0b0;
+}
+
+.foot .left .bold {
+  color: #a0a0a0;
+}
+
+.foot .left .bolder {
+  color: #808080;
+}
+
+.foot .right {
+  font-size: 15px;
+  font-weight: 500;
+  color: #a0a0a0;
+}
+
+.foot a {
+  opacity: .5;
+}
+
+.foot a:focus,
+.foot a:hover {
+  opacity: 1;
+}
+
+.foot img {
+  height: 24px;
+  vertical-align: middle;
+}
+
+.timer {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  background-color: #ffffff;
+  color: #b0b0c0;
+  height: 100%;
+  width: 100%;
+  padding-top: 10vh;
+}
+
+.timer.bip, .timer.bip .time input {
+  background-color: #ff9966;
+}
+
+.timer.bip .time input {
+  border-color: #ff9966;
+}
+
+.timer.bip .time .up.hid {
+  border-bottom-color: #ff9966;
+}
+
+.timer.bip .time .down.hid {
+  border-top-color: #ff9966;
+}
+
+.timer.bop, .timer.bop .time input {
+  background-color: #ffe5b4;
+}
+
+.timer.bop .time input {
+  border-color: #ffe5b4;
+}
+
+.timer.bop .time .up.hid {
+  border-bottom-color: #ffe5b4;
+}
+
+.timer.bop .time .down.hid {
+  border-top-color: #ffe5b4;
+}
+
+.timer.beep .time,
+.timer.beep .time input,
+.timer.beep .info .count,
+.timer.beep .info .sound {
+  color: #606060;
+}
+
+.timer.beep .time input:focus,
+.timer.beep .time input:hover {
+  color: inherit;
+}
+
+.timer .info {
+  display: flex;
+  justify-content: space-between;
+  width: 62vw;
+}
+
+.timer .info .count,
+.timer .info .sound {
+  font-size: 2vw;
+}
+
+.timer .info .sound .label {
+  font-weight: 500;
+}
+
+.timer .time,
+.timer .time input {
+  font-size: 12vw;
+  font-weight: 500;
+  color: #c0c0d0;
+}
+
+.timer .time {
+  display: flex;
+  align-items: center;
+  margin: 0 .5vw 0 0;
+  min-height: 25vw;
+}
+
+.timer .time.running,
+.timer .time.running input {
+  color: #000000;
+}
+
+.timer .time .hour,
+.timer .time .minute,
+.timer .time .second {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+.timer .time input {
+  display: inline-block;
+  background-color: #f0f0ff;
+  margin: 0px -1vw 0 -.5vw;
+  padding: .4vw 0 0 1.2vw;
+  border: 2px dashed #d0d0e0;
+  border-radius: 8px;
+  width: 17vw;
+}
+
+.timer .time input:focus,
+.timer .time input:hover {
+  color: #a0a0b0;
+}
+
+.timer .time.running input:focus,
+.timer .time.running input:hover {
+  color: inherit;
+}
+
+.timer .time.running input {
+  background-color: #ffffff;
+  border-color: #ffffff;
+}
+
+.timer .time .up,
+.timer .time .down {
+  cursor: pointer;
+  height: 0;
+  width: 0;
+  margin: 2vh;
+  border-left: 3vw solid transparent;
+  border-right: 3vw solid transparent;
+}
+
+.timer .time .up {
+  border-bottom: 2.5vw solid #e0e0f0;
+}
+
+.timer .time .down {
+  border-top: 2.5vw solid #e0e0f0;
+}
+
+.timer .time .up:focus,
+.timer .time .up:hover {
+  border-bottom-color: #b0b0c0;
+}
+
+.timer .time .down:focus,
+.timer .time .down:hover {
+  border-top-color: #b0b0c0;
+}
+
+.timer .time .up.hid,
+.timer .time .down.hid {
+  cursor: default;
+}
+
+.timer .time .up.hid {
+  border-bottom-color: #ffffff;
+}
+
+.timer .time .down.hid {
+  border-top-color: #ffffff;
+}
+
+.timer .time .down.dim {
+  cursor: not-allowed;
+  border-top-color: #f4f4ff;
+}
+
+.timer .button,
+.timer .stop-button {
+  cursor: pointer;
+  font-size: 4vw;
+  border: none;
+}
+
+.timer .button {
+  background-color: #e0e0e0;
+  color: #606060;
+  min-height: 1.5em;
+  margin-top: 1vh;
+  padding: 0 2vw .4vw 2vw;
+  border-radius: 4px;
+  border-bottom: 3px solid #c0c0c0;
+}
+
+.timer .button:focus,
+.timer .button:hover {
+  background-color: #e6e6fa;
+  color: #796878;
+  border-color: #d6cadd;
+}
+
+.timer .button.disabled {
+  cursor: not-allowed;
+  background-color: #f0f0f0;
+  color: #d0d0d0;
+  border-bottom-color: #e0e0e0;
+}
+
+.timer .stop-button {
+  background: inherit;
+  color: #b0b0b0;
+  margin-top: 2vh;
+  padding: 0 2vw .6vw 2vw;
+}
+
+.timer .stop-button:focus,
+.timer .stop-button:hover {
+  color: #404040;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util/index.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,7 @@
+import {prod} from '_webpackconfig'
+
+const prefix = (path) => (prod ? '/dev/woke' : '').concat(path)
+
+export {
+  prefix
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webpack.config.js	Mon Mar 08 19:16:18 2021 +0000
@@ -0,0 +1,40 @@
+const path = require('path')
+
+module.exports = (env = {}) => {
+  const cfg = {
+    entry: ['babel-polyfill', './index.js'],
+    output: {
+      path: path.resolve(__dirname, './pub/dist'),
+      filename: 'woke.js'
+    },
+    module: {
+      rules: [{
+        test: /\.js$/,
+        exclude: /node_modules/,
+        use: {
+          loader: 'babel-loader'
+        }
+      }]
+    },
+    plugins: [],
+    externals: {
+      _webpackconfig: {
+        prod: false
+      }
+    }
+  }
+
+  if (env.prod === true) {
+    const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
+    cfg.plugins = cfg.plugins.concat([new UglifyJSPlugin()])
+    cfg.externals._webpackconfig.prod = true
+  } else {
+    cfg.devServer = {
+      contentBase: './pub'
+    }
+  }
+
+  cfg.externals._webpackconfig = JSON.stringify(cfg.externals._webpackconfig)
+
+  return cfg
+}