| 5 | import pkg from './package.json'; |
| 6 | |
| 7 | const createConfig = ({ output, min = false }) => { |
| 8 | const minify = |
| 9 | min && |
| 10 | terser({ |
| 11 | output: { |
| 12 | comments(_, { text, type }) { |
| 13 | if (type === 'comment2') { |
| 14 | // multiline comment |
| 15 | return /@preserve|@license|@cc_on/i.test(text); |
| 16 | } |
| 17 | }, |
| 18 | }, |
| 19 | }); |
| 20 | |
| 21 | const plugins = [ |
| 22 | // https://github.com/rollup/rollup-plugin-node-resolve#usage |
| 23 | resolve(), |
| 24 | // Resolve source maps to the original source |
| 25 | sourceMaps(), |
| 26 | minify, |
| 27 | ]; |
| 28 | |
| 29 | if (output.format !== 'esm') { |
| 30 | // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs) |
| 31 | plugins.unshift(commonjs()); |
| 32 | } |
| 33 | |
| 34 | return { |
| 35 | input: 'dist/es/perfume.js', |
| 36 | output: { |
| 37 | file: output.file, |
| 38 | format: output.format, |
| 39 | name: 'Perfume', |
| 40 | sourcemap: true |
| 41 | }, |
| 42 | watch: { include: 'dist/es/**' }, |
| 43 | plugins: plugins.filter(Boolean), |
| 44 | }; |
| 45 | }; |
| 46 | |
| 47 | export default [ |
| 48 | createConfig({ |