|
| 1 | +const { uglify } = require('rollup-plugin-uglify'); |
| 2 | +const json = require('rollup-plugin-json'); |
| 3 | +const postcss = require('rollup-plugin-postcss'); |
| 4 | +const babel = require('rollup-plugin-babel'); |
| 5 | +const resolve = require('rollup-plugin-node-resolve'); |
| 6 | +const commonjs = require('rollup-plugin-commonjs'); |
| 7 | +const { string } = require('rollup-plugin-string'); |
| 8 | +const context = require('rollup-plugin-require-context'); |
| 9 | +const builtins = require('rollup-plugin-node-builtins'); |
| 10 | +const bundleWorker = require('../libs/worker'); |
| 11 | +const analyzer = require('rollup-plugin-visualizer'); |
| 12 | + |
| 13 | +const defaultRollup = { |
| 14 | + input: 'src/index.js', |
| 15 | + name: 'Player', |
| 16 | + sourcemap: true, |
| 17 | + production: false, |
| 18 | + external: [], |
| 19 | + plugins: [], |
| 20 | + globals: {}, |
| 21 | + commonjs: {}, |
| 22 | + resolve: {}, |
| 23 | + babel: {}, |
| 24 | + watch: {} |
| 25 | +}; |
| 26 | + |
| 27 | +const commonRollup = function (config = {}) { |
| 28 | + const rollupConfig = Object.assign({}, defaultRollup, config); |
| 29 | + return { |
| 30 | + input: rollupConfig.input, |
| 31 | + output: config.output || [ |
| 32 | + { |
| 33 | + file: rollupConfig.uglify ? 'dist/index.min.js' : 'dist/index.js', |
| 34 | + name: rollupConfig.name, |
| 35 | + format: 'umd', |
| 36 | + sourcemap: uglify ? false : rollupConfig.sourcemap, |
| 37 | + globals: rollupConfig.globals |
| 38 | + } |
| 39 | + ], |
| 40 | + external: rollupConfig.external, |
| 41 | + plugins: [ |
| 42 | + ...rollupConfig.plugins, |
| 43 | + bundleWorker(), |
| 44 | + rollupConfig.uglify ? uglify(rollupConfig.uglify) : undefined, |
| 45 | + json({ |
| 46 | + compact: true |
| 47 | + }), |
| 48 | + postcss({ |
| 49 | + extensions: ['.css', '.scss', '.sass'], |
| 50 | + 'postcss-cssnext': { |
| 51 | + browserslist: ['cover 99.5%'] |
| 52 | + } |
| 53 | + }), |
| 54 | + babel({ |
| 55 | + exclude: ['node_modules/**', '**/*.svg'], |
| 56 | + ...rollupConfig.babel |
| 57 | + }), |
| 58 | + resolve({ |
| 59 | + preferBuiltins: true, |
| 60 | + extensions: ['.mjs', '.js', '.jsx', '.json'], |
| 61 | + ...rollupConfig.resolve |
| 62 | + }), |
| 63 | + string({ |
| 64 | + include: '**/*.svg' |
| 65 | + }), |
| 66 | + commonjs({ |
| 67 | + include: [/node_modules/], |
| 68 | + ...rollupConfig.commonjs |
| 69 | + }), |
| 70 | + builtins(), |
| 71 | + context(), |
| 72 | + process.env.ANALYZE ? analyzer() : undefined |
| 73 | + ], |
| 74 | + watch: { |
| 75 | + ...config.watch |
| 76 | + } |
| 77 | + }; |
| 78 | +}; |
| 79 | +module.exports = commonRollup; |
0 commit comments