1 | import fs from 'fs';
|
2 | import path from 'path';
|
3 | import { minify } from 'uglify-js';
|
4 | import buble from 'rollup-plugin-buble';
|
5 | import commonjs from 'rollup-plugin-commonjs';
|
6 | import json from 'rollup-plugin-json';
|
7 | import saveLicense from 'uglify-save-license';
|
8 | import stripBanner from 'rollup-plugin-strip-banner';
|
9 |
|
10 |
|
11 |
|
12 | const SRC_DIR = path.resolve('resource');
|
13 | const DIST_DIR = path.resolve('dist');
|
14 |
|
15 | export default {
|
16 | input: path.join(SRC_DIR, 'index.js'),
|
17 | output: {
|
18 |
|
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 | };
|