Mirror: 馃帺 A tiny but capable push & pull stream library for TypeScript and Flow
at v4.0.12 4.2 kB view raw
1import { resolve, basename } from 'path'; 2import commonjs from '@rollup/plugin-commonjs'; 3import nodeResolve from '@rollup/plugin-node-resolve'; 4import typescript from 'rollup-plugin-typescript2'; 5import buble from '@rollup/plugin-buble'; 6import babel from 'rollup-plugin-babel'; 7import { terser } from 'rollup-plugin-terser'; 8import compiler from '@ampproject/rollup-plugin-closure-compiler'; 9 10import minifyBucklescript from './scripts/minify-bucklescript-plugin'; 11 12const cwd = process.cwd(); 13const pkgInfo = require('./package.json'); 14const name = basename(pkgInfo.main, '.js'); 15 16const terserPretty = terser({ 17 sourcemap: true, 18 warnings: true, 19 ecma: 5, 20 keep_fnames: true, 21 ie8: false, 22 compress: { 23 pure_getters: true, 24 toplevel: true, 25 booleans_as_integers: false, 26 keep_fnames: true, 27 keep_fargs: true, 28 if_return: false, 29 ie8: false, 30 sequences: false, 31 loops: false, 32 conditionals: false, 33 join_vars: false, 34 }, 35 mangle: false, 36 output: { 37 beautify: true, 38 braces: true, 39 indent_level: 2, 40 }, 41}); 42 43const terserMinified = terser({ 44 sourcemap: true, 45 warnings: true, 46 ecma: 5, 47 ie8: false, 48 toplevel: true, 49 mangle: true, 50 compress: { 51 keep_infinity: true, 52 pure_getters: true, 53 passes: 10, 54 }, 55 output: { 56 comments: false, 57 }, 58}); 59 60const importAllPlugin = ({ types: t }) => ({ 61 visitor: { 62 VariableDeclarator(path) { 63 if ( 64 t.isIdentifier(path.node.id) && 65 t.isCallExpression(path.node.init) && 66 t.isIdentifier(path.node.init.callee) && 67 path.node.init.callee.name === 'require' && 68 path.node.init.arguments.length === 1 69 ) { 70 path.parentPath.replaceWith( 71 t.importDeclaration( 72 [t.importNamespaceSpecifier(path.node.id)], 73 path.node.init.arguments[0] 74 ) 75 ); 76 } 77 }, 78 }, 79}); 80 81const makePlugins = (isProduction) => 82 [ 83 babel({ 84 babelrc: false, 85 extensions: ['ts', 'tsx', 'js'], 86 exclude: 'node_modules/**', 87 presets: [], 88 plugins: ['@babel/plugin-syntax-typescript', importAllPlugin], 89 }), 90 typescript({ 91 typescript: require('typescript'), 92 cacheRoot: './node_modules/.cache/.rts2_cache', 93 useTsconfigDeclarationDir: true, 94 tsconfigOverride: { 95 compilerOptions: { 96 strict: false, 97 noUnusedParameters: false, 98 declaration: !isProduction, 99 declarationDir: resolve(cwd, './dist/types/'), 100 target: 'esnext', 101 module: 'es2015', 102 rootDir: cwd, 103 }, 104 }, 105 }), 106 commonjs({ 107 ignoreGlobal: true, 108 include: ['*', '**'], 109 extensions: ['.js', '.ts', '.tsx'], 110 }), 111 nodeResolve({ 112 mainFields: ['module', 'jsnext', 'main'], 113 extensions: ['.js', '.ts', '.tsx'], 114 browser: true, 115 }), 116 buble({ 117 transforms: { 118 unicodeRegExp: false, 119 dangerousForOf: true, 120 dangerousTaggedTemplateString: true, 121 }, 122 objectAssign: 'Object.assign', 123 exclude: 'node_modules/**', 124 }), 125 babel({ 126 babelrc: false, 127 extensions: ['ts', 'tsx', 'js'], 128 exclude: 'node_modules/**', 129 presets: [], 130 plugins: ['babel-plugin-closure-elimination'], 131 }), 132 minifyBucklescript(), 133 compiler({ 134 formatting: 'PRETTY_PRINT', 135 compilation_level: 'SIMPLE_OPTIMIZATIONS', 136 }), 137 isProduction ? terserMinified : terserPretty, 138 ].filter(Boolean); 139 140const config = { 141 input: './src/Wonka.ts', 142 onwarn: () => {}, 143 external: () => false, 144 treeshake: { 145 propertyReadSideEffects: false, 146 }, 147}; 148 149export default [ 150 { 151 ...config, 152 plugins: makePlugins(false), 153 output: [ 154 { 155 legacy: true, 156 freeze: false, 157 esModule: false, 158 file: `./dist/${name}.js`, 159 format: 'cjs', 160 }, 161 { 162 compact: true, 163 file: `./dist/${name}.mjs`, 164 format: 'esm', 165 }, 166 ], 167 }, 168 { 169 ...config, 170 plugins: makePlugins(true), 171 output: [ 172 { 173 legacy: true, 174 freeze: false, 175 esModule: false, 176 file: `./dist/${name}.min.js`, 177 format: 'cjs', 178 }, 179 ], 180 }, 181];