Skip to content

Instantly share code, notes, and snippets.

@porsager
Forked from cmnstmntmn/package.json
Last active September 13, 2016 19:59
Show Gist options
  • Save porsager/30253d5065a65e9ddc407caf97f1d19c to your computer and use it in GitHub Desktop.
Save porsager/30253d5065a65e9ddc407caf97f1d19c to your computer and use it in GitHub Desktop.
{
"name": "www",
"version": "1.0.0",
"scripts": {
"dev": "node tasks/wright.dev.js",
"prod": "node tasks/wright.prod.js"
},
"dependencies": {
"rollup": "^0.35.9",
"wright": "github:porsager/wright"
},
"devDependencies": {
"nib": "^1.1.2",
"postcss": "^5.2.0",
"rollup-plugin-commonjs": "^4.1.0",
"rollup-plugin-json": "^2.0.2",
"rollup-plugin-node-resolve": "^2.0.0",
"stylus": "^0.54.5"
}
}
const fs = require('fs')
, chokidar = require('chokidar')
, rollup = require('rollup')
, commonjs = require('rollup-plugin-commonjs')
, json = require('rollup-plugin-json')
, nodeResolve = require('rollup-plugin-node-resolve')
, stylus = require('stylus')
, nib = require('nib')
, wright = require('wright')
roll()
.then(style())
.then(() => {
chokidar
.watch('resources/js/**/*.js', { ignoreInitial: true })
.on('all', () => roll())
chokidar
.watch('resources/css/**/*.styl', { ignoreInitial: true })
.on('all', () => style())
wright({
main: 'http://my-www.dev',
serve: 'public',
fps: true,
debug: true,
run: 'window.reload()',
watch: '**/*.php'
})
})
.catch(err => {
throw err
})
function roll() {
return rollup.rollup({
entry: 'resources/js/app.js'
}).then(bundle => {
bundle.write({
format: 'iife',
dest: 'public/js/bundle.js'
})
})
}
function style() {
return new Promise((resolve, reject) => {
fs.readFile('resources/css/app.styl', 'utf8', (err, str) => {
if (err)
return reject(err)
stylus(str)
.set('filename', 'resources/css/app.styl')
.use(nib())
.import('nib')
.render((err, css) => {
fs.writeFileSync('public/css/style.css', css, 'utf8')
return err ? reject(err) : resolve(css)
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment