64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
|
|
import typescript from '@rollup/plugin-typescript';
|
||
|
|
import resolve from '@rollup/plugin-node-resolve';
|
||
|
|
import commonjs from '@rollup/plugin-commonjs';
|
||
|
|
import { default as terser } from '@rollup/plugin-terser';
|
||
|
|
import bundleSize from 'rollup-plugin-bundle-size';
|
||
|
|
|
||
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
||
|
|
|
||
|
|
// Shared configuration
|
||
|
|
const createConfig = (input, outputFile, external = []) => ({
|
||
|
|
input,
|
||
|
|
external: ['react', 'react-native', 'react/jsx-runtime', ...external],
|
||
|
|
output: [
|
||
|
|
{
|
||
|
|
file: `dist/${outputFile}.js`,
|
||
|
|
format: 'cjs',
|
||
|
|
sourcemap: !isProduction,
|
||
|
|
exports: 'named',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
file: `dist/${outputFile}.esm.js`,
|
||
|
|
format: 'esm',
|
||
|
|
sourcemap: !isProduction,
|
||
|
|
},
|
||
|
|
],
|
||
|
|
plugins: [
|
||
|
|
resolve({
|
||
|
|
preferBuiltins: false,
|
||
|
|
}),
|
||
|
|
commonjs(),
|
||
|
|
typescript({
|
||
|
|
tsconfig: './tsconfig.json',
|
||
|
|
declaration: true,
|
||
|
|
declarationDir: './dist',
|
||
|
|
rootDir: './src',
|
||
|
|
exclude: ['**/*.test.*', '**/*.spec.*'],
|
||
|
|
}),
|
||
|
|
...(isProduction ? [terser({
|
||
|
|
compress: {
|
||
|
|
pure_getters: true,
|
||
|
|
unsafe: true,
|
||
|
|
unsafe_comps: true,
|
||
|
|
},
|
||
|
|
mangle: {
|
||
|
|
properties: {
|
||
|
|
regex: /^_/,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
})] : []),
|
||
|
|
bundleSize(),
|
||
|
|
],
|
||
|
|
treeshake: {
|
||
|
|
moduleSideEffects: false,
|
||
|
|
propertyReadSideEffects: false,
|
||
|
|
unknownGlobalSideEffects: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
export default [
|
||
|
|
createConfig('src/index.ts', 'index'),
|
||
|
|
createConfig('src/react.tsx', 'react'),
|
||
|
|
createConfig('src/react-native.tsx', 'react-native'),
|
||
|
|
];
|