|
| 1 | +import commonjs from 'rollup-plugin-commonjs' |
| 2 | +import nodeResolve from 'rollup-plugin-node-resolve' |
| 3 | +import buble from 'rollup-plugin-buble' |
| 4 | +import babel from 'rollup-plugin-babel' |
| 5 | +import { terser } from 'rollup-plugin-terser' |
| 6 | +import replace from 'rollup-plugin-replace' |
| 7 | + |
| 8 | +const pkgInfo = require('./package.json') |
| 9 | +const { peerDependencies, dependencies } = pkgInfo |
| 10 | + |
| 11 | +let external = ['dns', 'fs', 'path', 'url'] |
| 12 | + |
| 13 | +if (pkgInfo.peerDependencies) { |
| 14 | + external.push(...Object.keys(peerDependencies)) |
| 15 | +} |
| 16 | + |
| 17 | +if (pkgInfo.dependencies) { |
| 18 | + external.push(...Object.keys(dependencies)) |
| 19 | +} |
| 20 | + |
| 21 | +const externalPredicate = new RegExp(`^(${external.join('|')})($|/)`) |
| 22 | +const externalTest = id => { |
| 23 | + if (id === 'babel-plugin-transform-async-to-promises/helpers') { |
| 24 | + return false |
| 25 | + } |
| 26 | + |
| 27 | + return externalPredicate.test(id) |
| 28 | +} |
| 29 | + |
| 30 | +const terserPretty = terser({ |
| 31 | + sourcemap: true, |
| 32 | + warnings: true, |
| 33 | + ecma: 5, |
| 34 | + keep_fnames: true, |
| 35 | + ie8: false, |
| 36 | + compress: { |
| 37 | + pure_getters: true, |
| 38 | + toplevel: true, |
| 39 | + booleans_as_integers: false, |
| 40 | + keep_fnames: true, |
| 41 | + keep_fargs: true, |
| 42 | + if_return: false, |
| 43 | + ie8: false, |
| 44 | + sequences: false, |
| 45 | + loops: false, |
| 46 | + conditionals: false, |
| 47 | + join_vars: false |
| 48 | + }, |
| 49 | + mangle: false, |
| 50 | + output: { |
| 51 | + beautify: true, |
| 52 | + braces: true, |
| 53 | + indent_level: 2 |
| 54 | + } |
| 55 | +}) |
| 56 | + |
| 57 | +const terserMinified = terser({ |
| 58 | + sourcemap: true, |
| 59 | + warnings: true, |
| 60 | + ecma: 5, |
| 61 | + ie8: false, |
| 62 | + toplevel: true, |
| 63 | + compress: { |
| 64 | + keep_infinity: true, |
| 65 | + pure_getters: true, |
| 66 | + passes: 10 |
| 67 | + }, |
| 68 | + output: { |
| 69 | + comments: false |
| 70 | + } |
| 71 | +}) |
| 72 | + |
| 73 | +const makePlugins = (isProduction = false) => [ |
| 74 | + babel({ |
| 75 | + babelrc: false, |
| 76 | + exclude: 'node_modules/**', |
| 77 | + presets: [], |
| 78 | + plugins: ['@babel/plugin-transform-flow-strip-types'] |
| 79 | + }), |
| 80 | + nodeResolve({ |
| 81 | + mainFields: ['module', 'jsnext', 'main'], |
| 82 | + browser: true |
| 83 | + }), |
| 84 | + commonjs({ |
| 85 | + ignoreGlobal: true, |
| 86 | + include: /\/node_modules\//, |
| 87 | + namedExports: { |
| 88 | + react: Object.keys(require('react')) |
| 89 | + } |
| 90 | + }), |
| 91 | + buble({ |
| 92 | + transforms: { |
| 93 | + unicodeRegExp: false, |
| 94 | + dangerousForOf: true, |
| 95 | + dangerousTaggedTemplateString: true |
| 96 | + }, |
| 97 | + objectAssign: 'Object.assign', |
| 98 | + exclude: 'node_modules/**' |
| 99 | + }), |
| 100 | + babel({ |
| 101 | + babelrc: false, |
| 102 | + exclude: 'node_modules/**', |
| 103 | + presets: [], |
| 104 | + plugins: [ |
| 105 | + 'babel-plugin-closure-elimination', |
| 106 | + '@babel/plugin-transform-object-assign', |
| 107 | + [ |
| 108 | + 'babel-plugin-transform-async-to-promises', |
| 109 | + { |
| 110 | + inlineHelpers: true, |
| 111 | + externalHelpers: true |
| 112 | + } |
| 113 | + ] |
| 114 | + ] |
| 115 | + }), |
| 116 | + isProduction && |
| 117 | + replace({ |
| 118 | + 'process.env.NODE_ENV': JSON.stringify('production') |
| 119 | + }), |
| 120 | + isProduction ? terserMinified : terserPretty |
| 121 | +] |
| 122 | + |
| 123 | +const config = { |
| 124 | + input: './src/index.js', |
| 125 | + onwarn: () => {}, |
| 126 | + external: externalTest, |
| 127 | + treeshake: { |
| 128 | + propertyReadSideEffects: false |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +const name = 'react-ssr-prepass' |
| 133 | + |
| 134 | +export default [ |
| 135 | + { |
| 136 | + ...config, |
| 137 | + plugins: makePlugins(false), |
| 138 | + output: [ |
| 139 | + { |
| 140 | + sourcemap: true, |
| 141 | + legacy: true, |
| 142 | + freeze: false, |
| 143 | + esModule: false, |
| 144 | + file: `./dist/${name}.development.js`, |
| 145 | + format: 'cjs' |
| 146 | + } |
| 147 | + ] |
| 148 | + }, |
| 149 | + { |
| 150 | + ...config, |
| 151 | + plugins: makePlugins(true), |
| 152 | + output: [ |
| 153 | + { |
| 154 | + sourcemap: true, |
| 155 | + legacy: true, |
| 156 | + freeze: false, |
| 157 | + file: `./dist/${name}.production.min.js`, |
| 158 | + format: 'cjs' |
| 159 | + } |
| 160 | + ] |
| 161 | + } |
| 162 | +] |
0 commit comments