From ad2a7aba5904d198d8ace6dfccc1f4aa871c7b4c Mon Sep 17 00:00:00 2001 From: romainmenke Date: Tue, 16 Nov 2021 20:05:34 +0100 Subject: [PATCH] shared rollup config --- rollup/default.js | 91 ++++++++++++++++++++++++++++++++++++++++++++ rollup/default.ts.js | 86 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 rollup/default.js create mode 100644 rollup/default.ts.js diff --git a/rollup/default.js b/rollup/default.js new file mode 100644 index 000000000..0c816deda --- /dev/null +++ b/rollup/default.js @@ -0,0 +1,91 @@ +import babel from '@rollup/plugin-babel'; +import commonjs from '@rollup/plugin-commonjs'; +import path from 'path'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import { terser } from 'rollup-plugin-terser'; + +export default [ + { + input: 'src/index.js', + output: [ + { file: 'dist/index.cjs', format: 'cjs', sourcemap: true, exports: 'auto' }, + { file: 'dist/index.mjs', format: 'esm', sourcemap: true, exports: 'auto' }, + ], + onwarn: (warning) => { + // Silence circular dependency warning for postcss-values-parsers package + if ( + warning.code === 'CIRCULAR_DEPENDENCY' && + warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1 + ) { + return; + } + + console.warn(`(!) ${warning.message}`); + }, + plugins: [ + babel({ + babelHelpers: 'bundled', + exclude: 'node_modules/**', + presets: [ + ['@babel/preset-env', { + corejs: 3, + loose: true, + modules: false, + targets: { node: 12 }, + useBuiltIns: 'usage', + }], + ], + }), + terser(), + ], + }, + { + input: 'src/cli.js', + output: [ + { file: 'dist/cli.mjs', format: 'esm', sourcemap: false }, + ], + onwarn: (warning) => { + // Silence circular dependency warning for postcss-values-parsers package + if ( + warning.code === 'CIRCULAR_DEPENDENCY' && + warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1 + ) { + return; + } + + console.warn(`(!) ${warning.message}`); + }, + plugins: [ + commonjs(), + nodeResolve({ + rootDir: path.join(process.cwd(), '..', '..'), + }), + babel({ + babelHelpers: 'bundled', + exclude: 'node_modules/**', + presets: [ + ['@babel/preset-env', { + corejs: 3, + loose: true, + modules: false, + targets: { node: 12 }, + useBuiltIns: 'usage', + }], + ], + }), + terser(), + addHashBang(), + ], + }, +]; + +function addHashBang () { + return { + name: 'add-hash-bang', + renderChunk (code) { + const updatedCode = `#!/usr/bin/env node\n\n${code}`; + + return updatedCode; + }, + }; +} diff --git a/rollup/default.ts.js b/rollup/default.ts.js new file mode 100644 index 000000000..ea69e1736 --- /dev/null +++ b/rollup/default.ts.js @@ -0,0 +1,86 @@ +import babel from '@rollup/plugin-babel'; +import commonjs from '@rollup/plugin-commonjs'; +import path from 'path'; +import typescript from '@rollup/plugin-typescript'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; +import { terser } from 'rollup-plugin-terser'; + +export default [ + { + input: 'src/index.ts', + output: [ + { file: 'dist/index.cjs', format: 'cjs', sourcemap: true, exports: 'auto' }, + { file: 'dist/index.mjs', format: 'esm', sourcemap: true, exports: 'auto' }, + ], + external: [ + 'postcss-values-parser', + ], + plugins: [ + typescript({ tsconfig: './tsconfig.json' }), + babel({ + babelHelpers: 'bundled', + exclude: 'node_modules/**', + presets: [ + ['@babel/preset-env', { + corejs: 3, + loose: true, + modules: false, + targets: { node: 12 }, + useBuiltIns: 'usage', + }], + ], + }), + terser(), + ], + }, + { + input: 'src/cli.ts', + output: [ + { file: 'dist/cli.mjs', format: 'esm', sourcemap: false }, + ], + onwarn: (warning) => { + // Silence circular dependency warning for postcss-values-parsers package + if ( + warning.code === 'CIRCULAR_DEPENDENCY' && + warning.importer.indexOf('node_modules/postcss-values-parser/lib') > -1 + ) { + return; + } + + console.warn(`(!) ${warning.message}`); + }, + plugins: [ + typescript({ tsconfig: './tsconfig.json' }), + commonjs(), + nodeResolve({ + rootDir: path.join(process.cwd(), '..', '..'), + }), + babel({ + babelHelpers: 'bundled', + exclude: 'node_modules/**', + presets: [ + ['@babel/preset-env', { + corejs: 3, + loose: true, + modules: false, + targets: { node: 12 }, + useBuiltIns: 'usage', + }], + ], + }), + terser(), + addHashBang(), + ], + }, +]; + +function addHashBang () { + return { + name: 'add-hash-bang', + renderChunk (code) { + const updatedCode = `#!/usr/bin/env node\n\n${code}`; + + return updatedCode; + }, + }; +}