Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
feat(build): add browserify (#93)
Browse files Browse the repository at this point in the history
* add browserify

* add watchify (takes <0.5s to compile)
  • Loading branch information
juliangruber authored and yoshuawuyts committed Dec 1, 2016
1 parent 88ab596 commit ccd50b4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ public/css/main.css
dmgs
npm-debug.log
build/background.tiff
bundle.js
6 changes: 1 addition & 5 deletions app.js
Expand Up @@ -11,11 +11,7 @@ const app = choo()
app.use(log())

// import & init models
const globs = bulk(__dirname, [ 'models/*' ])
Object.keys(globs).forEach((globname) => {
const globmatch = globs[globname]
Object.keys(globmatch).forEach((key) => app.model(globmatch[key]()))
})
app.model(require('./models/app')())

// start
app.router(['/', mainView])
Expand Down
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -6,6 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<script>require('./app')</script>
<script>require('./bundle')</script>
</body>
</html>
19 changes: 19 additions & 0 deletions lib/transform.js
@@ -0,0 +1,19 @@
'use strict'

const through = require('through2')

module.exports = file => {
if (!/\.js$/.test(file)) return through()
let src = ''
const out = through((chunk, _, cb) => {
src += chunk
cb()
}, function (cb) {
src = src.replace(/require\('bindings'\)\('(.*)'\)/, (_, bindings) =>
`require('bindings')({ bindings: '${bindings}', module_root: __dirname })`
)
this.push(src)
cb()
})
return out
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -34,6 +34,8 @@
"scripts": {
"build-app": "electron-packager . Dat --platform=darwin --arch=x64 --out=dist/ --overwrite --extend-info extend.plist --app-bundle-id=com.dat.desktop --icon=public/img/app.icns",
"build-dmg": "appdmg dmg.json dist/Dat-$npm_package_version.dmg && rm -Rf dist/Dat-darwin-x64",
"bundle": "browserify --fast --ignore-missing --node --full-paths --exclude=electron --global-transform=./lib/transform.js app.js > bundle.js",
"watch-js": "watchify --fast --ignore-missing --node --full-paths --exclude=electron --global-transform=./lib/transform.js app.js --verbose -o bundle.js",
"deps": "dependency-check package.json app.js",
"package": "npm run build-app && npm run build-dmg",
"rebuild": "./scripts/build rebuild",
Expand All @@ -49,14 +51,17 @@
},
"devDependencies": {
"appdmg": "^0.4.5",
"browserify": "^13.1.1",
"bulkify": "^1.4.2",
"dependency-check": "^2.6.0",
"electron": "1.4.6",
"electron-builder": "^8.6.0",
"node-sass": "^3.8.0",
"node-sass-magic-importer": "^1.0.1",
"nodemon": "^1.9.2",
"standard": "^7.1.2"
"standard": "^7.1.2",
"through2": "^2.0.3",
"watchify": "^3.7.0"
},
"build": {
"appId": "com.datproject.dat",
Expand Down

0 comments on commit ccd50b4

Please sign in to comment.