Skip to content

Instantly share code, notes, and snippets.

@porsager
Created September 13, 2016 09:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save porsager/6f51a4ee5ec9647d63809aed26407745 to your computer and use it in GitHub Desktop.
Save porsager/6f51a4ee5ec9647d63809aed26407745 to your computer and use it in GitHub Desktop.
console.time('build')
const fs = require('fs-extra')
, rollup = require('rollup')
, commonjs = require('rollup-plugin-commonjs')
, json = require('rollup-plugin-json')
, nodeResolve = require('rollup-plugin-node-resolve')
, buble = require('rollup-plugin-buble')
, uglify = require('rollup-plugin-uglify')
, stylus = require('stylus')
, nib = require('nib')
fs.copySync('./static', './public', { clobber: true })
fs.ensureDir('./public/css')
fs.ensureDir('./public/js')
module.exports = rollup.rollup({
entry: 'src/app.js',
plugins: [
json(),
commonjs(),
nodeResolve(),
buble(),
uglify({ mangle: true, compress: true })
]
})
.then(bundle => {
bundle.write({
format: 'iife',
dest: 'public/js/app.js',
sourceMap: true
})
}).catch(e => {
console.error(e)
process.exit(1)
})
const style = stylus(fs.readFileSync('src/css/style.styl', 'utf8'))
.set('filename', 'src/css/style.styl')
.set('compress', true)
.set('sourcemap', {})
.use(nib())
.import('nib')
style.render((err, css) => {
if (err)
throw err
fs.writeFileSync('public/css/style.css', css.replace('URL=src/css/', 'URL='), 'utf8')
fs.writeFileSync('public/css/style.css.map', JSON.stringify(style.sourcemap), 'utf8')
})
process.on('exit', () => console.timeEnd('build'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment