-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild.js
54 lines (47 loc) · 1.74 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* brightwheel
*
* Copyright © 2016 Allen Smith <[email protected]>. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
'use strict';
const fs = require('fs');
const del = require('del');
const rollup = require('rollup');
const babel = require('rollup-plugin-babel');
const pkg = require('../package.json');
let promise = Promise.resolve();
// Clean up the output directory
promise = promise.then(() => del(['dist/*']));
// Compile source code into a distributable format with Babel
for (const format of ['es6', 'cjs', 'umd', 'iife', 'amd']) {
promise = promise.then(() => rollup.rollup({
entry: 'src/index.js',
external: Object.keys(pkg.dependencies),
plugins: [babel(Object.assign(pkg.babel, {
babelrc: false,
exclude: 'node_modules/**',
runtimeHelpers: true,
presets: pkg.babel.presets.map(x => (x === 'es2015' ? 'es2015-rollup' : x)),
}))],
}).then(bundle => bundle.write({
dest: `dist/${format === 'cjs' ? 'index' : `index.${format}`}.js`,
format,
sourceMap: true,
moduleName: pkg.name //format === 'umd' ? pkg.name : undefined,
})));
}
// Copy package.json, LICENSE.txt, and README.md
promise = promise.then(() => {
delete pkg.private;
delete pkg.devDependencies;
delete pkg.scripts;
delete pkg.eslintConfig;
delete pkg.babel;
fs.writeFileSync('dist/package.json', JSON.stringify(pkg, null, ' '), 'utf-8');
fs.writeFileSync('dist/LICENSE.txt', fs.readFileSync('LICENSE.txt', 'utf-8'), 'utf-8');
fs.writeFileSync('dist/README.md', fs.readFileSync('README.md', 'utf-8'), 'utf-8')
});
promise.catch(err => console.error(err.stack)); // eslint-disable-line no-console