Created
July 29, 2022 10:37
-
-
Save Toyurc/03506d956bf51ed51ec3749e03eca297 to your computer and use it in GitHub Desktop.
sample rollup file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable import/no-anonymous-default-export */ | |
import { nodeResolve } from '@rollup/plugin-node-resolve'; | |
import eslint from '@rollup/plugin-eslint'; | |
import commonjs from '@rollup/plugin-commonjs'; | |
import typescript from '@rollup/plugin-typescript'; | |
import external from 'rollup-plugin-peer-deps-external'; | |
import { terser } from 'rollup-plugin-terser'; | |
// import postcss from 'rollup-plugin-postcss'; | |
import babel from '@rollup/plugin-babel'; | |
import uglify from 'rollup-plugin-uglify'; | |
import { visualizer } from 'rollup-plugin-visualizer'; | |
import packageJson from './package.json'; | |
const isProduction = process.env.NODE_ENV === 'production'; | |
const extensions = ['.ts', '.tsx']; | |
export default { | |
input: './src/index.ts', | |
output: [ | |
{ | |
file: packageJson.main, | |
format: 'umd', | |
sourcemap: !isProduction, | |
name: 'index', | |
}, | |
{ | |
file: packageJson.common, | |
format: 'cjs', | |
sourcemap: !isProduction, | |
}, | |
{ | |
exports: 'named', | |
file: packageJson.module, | |
format: 'es', | |
sourcemap: !isProduction, | |
}, | |
], | |
plugins: [ | |
nodeResolve({ extensions }), | |
// postcss({ | |
// minimize: true, | |
// plugins: [], | |
// }), | |
babel({ | |
babelHelpers: 'runtime', | |
exclude: 'node_modules/**', | |
extensions, | |
presets: ['@babel/preset-react'], | |
}), | |
external(), | |
commonjs(), | |
typescript({ | |
exclude: [ | |
// Exclude test files | |
/\.test.((js|jsx|ts|tsx))$/, | |
// Exclude story files | |
/\.stories.((js|jsx|ts|tsx|mdx))$/, | |
], | |
tsconfig: './tsconfig.json', | |
}), | |
eslint({ exclude: ['src/styles/**'] }), | |
terser(), | |
visualizer(), | |
uglify.uglify(), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using es build
import pkg from "./package.json";
import esbuild from "rollup-plugin-esbuild";
import image from "@rollup/plugin-image";
import svgr from "@svgr/rollup";
import dts from "rollup-plugin-dts";
const bundle = (config) => ({
...config,
input: "src/index.ts",
});
const rollupConfig = [
bundle({
sourcemap: true,
external: ["react", "next"],
output: [
{ file: pkg.main, format: "cjs" },
{ file: pkg.module, format: "es" },
],
plugins: [
image(),
svgr(),
esbuild({
// All options are optional
include: /.[jt]sx?$/, // default, inferred from
loaders
optionminify: process.env.NODE_ENV === "production",
// Add extra loaders
// loaders: {
// // Add .json files support
// // require @rollup/plugin-commonjs
// ".json": "json",
// // Enable JSX in .js files too
// ".js": "jsx",
// },
}),
],
}),
bundle({
plugins: [dts()],
output: {
file: pkg.typings,
format: "es",
},
}),
];
export default rollupConfig;