UNPKG

1.45 kBJavaScriptView Raw
1import fs from 'fs';
2import path from 'path';
3import { minify } from 'uglify-js';
4import buble from 'rollup-plugin-buble';
5import commonjs from 'rollup-plugin-commonjs';
6import json from 'rollup-plugin-json';
7import saveLicense from 'uglify-save-license';
8import stripBanner from 'rollup-plugin-strip-banner';
9
10// const copyright = fs.readFileSync(path.join('resources', 'COPYRIGHT'), 'utf-8');
11
12const SRC_DIR = path.resolve('resource');
13const DIST_DIR = path.resolve('dist');
14
15export default {
16 input: path.join(SRC_DIR, 'index.js'),
17 output: {
18 // banner: copyright,
19 name: 'DataStructure',
20 exports: 'named',
21 file: path.join(DIST_DIR, 'data-structure.js'),
22 format: 'umd',
23 sourcemap: false,
24 },
25 transforms: { forOf: false },
26 plugins: [
27 commonjs(),
28 json(),
29 stripBanner(),
30 buble({
31 transforms: {
32 dangerousForOf: true
33 }
34 }),
35 {
36 name: 'uglify',
37 transformBundle(code) {
38 const result = minify(code, {
39 fromString: true,
40 mangle: { toplevel: true },
41 output: { max_line_len: 2048, comments: saveLicense },
42 compress: { comparisons: true, pure_getters: true, unsafe: true },
43 });
44
45 if (!fs.existsSync(DIST_DIR)) {
46 fs.mkdirSync(DIST_DIR);
47 }
48
49 fs.writeFileSync(
50 path.join(DIST_DIR, 'data-structure.min.js'),
51 result.code,
52 'utf8'
53 );
54 },
55 },
56 ],
57};