vanilla-tilt.js/build.js

102 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

2017-01-30 19:57:51 +01:00
import {rollup} from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import babelrc from 'babelrc-rollup';
2017-06-13 09:16:24 +02:00
import {minify} from 'uglify-es';
2017-01-29 21:03:03 +01:00
import fs from 'fs';
const pkg = require('./package.json');
const external = !!pkg.dependencies ? Object.keys(pkg.dependencies) : [];
2017-01-29 21:03:03 +01:00
/*
2017-01-30 19:57:51 +01:00
create the lib for publishing to npm
*/
2017-01-29 21:03:03 +01:00
rollup({
2017-01-30 19:57:51 +01:00
entry: 'src/vanilla-tilt.js',
plugins: [
nodeResolve({
module_es2015: true,
2017-01-30 19:57:51 +01:00
jsnext: true,
main: true,
})
],
external: external
}).then(bundle => bundle.write({
dest: pkg.module_es2015,
2017-01-30 19:57:51 +01:00
format: 'es'
})).catch(err => console.log(err.stack));
2017-01-29 21:03:03 +01:00
rollup({
2017-01-30 19:57:51 +01:00
entry: 'src/vanilla-tilt.js',
plugins: [
nodeResolve({
module_es2015: true,
2017-01-30 19:57:51 +01:00
jsnext: true,
main: true,
}),
babel(babelrc()),
commonjs()
],
external: external
}).then(bundle => bundle.write({
dest: pkg.main,
format: 'cjs'
})).catch(err => console.log(err.stack));
2017-01-29 21:03:03 +01:00
/*
2017-01-30 19:57:51 +01:00
create dist for using as script in html
*/
rollup({
2017-01-30 19:57:51 +01:00
entry: 'src/vanilla-tilt.js',
plugins: [
nodeResolve({
module_es2015: true,
2017-01-30 19:57:51 +01:00
jsnext: true,
main: true,
})
],
external: external
}).then((bundle) => {
bundle.write({
moduleName: 'VanillaTilt',
format: 'iife',
2017-02-23 23:27:03 +01:00
dest: pkg.distrib,
2017-01-30 19:57:51 +01:00
}).then(() => {
const code = minify(fs.readFileSync(pkg.distrib).toString()).code;
2017-01-30 19:57:51 +01:00
2017-02-23 23:27:03 +01:00
fs.writeFileSync(pkg.distrib.replace('.js', '.min.js'), code);
2017-01-30 19:57:51 +01:00
return bundle;
2017-01-29 21:03:03 +01:00
})
2017-01-30 19:57:51 +01:00
}).catch(err => console.log(err.stack));
rollup({
entry: 'src/vanilla-tilt.js',
plugins: [
nodeResolve({
module_es2015: true,
jsnext: true,
main: true
}),
babel(babelrc()),
2017-01-30 20:22:56 +01:00
commonjs()
],
external: external
2017-01-30 19:57:51 +01:00
}).then((bundle) => {
2017-02-23 23:27:03 +01:00
const dest = pkg.distrib.replace('.js', '.babel.js');
2017-01-29 21:03:03 +01:00
bundle.write({
2017-01-30 19:57:51 +01:00
moduleName: 'VanillaTilt',
format: 'iife',
dest: dest,
})
2017-01-29 21:03:03 +01:00
.then(() => {
const code = minify(fs.readFileSync(dest).toString()).code;
2017-01-29 21:03:03 +01:00
fs.writeFileSync(dest.replace('.js', '.min.js'), code);
return bundle;
})
2017-01-30 19:57:51 +01:00
}).catch(err => console.log(err.stack));