Skip to content

Instantly share code, notes, and snippets.

@sekoyo
Created July 18, 2021 15:07
Show Gist options
  • Save sekoyo/89b5a2548a4742abe912baf76bd0ba84 to your computer and use it in GitHub Desktop.
Save sekoyo/89b5a2548a4742abe912baf76bd0ba84 to your computer and use it in GitHub Desktop.
A component/library config for rollup
{
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs.js"
}
},
"types": "dist/index.d.ts",
}
/* eslint-env node */
import replace from '@rollup/plugin-replace'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import typescript from 'rollup-plugin-typescript2'
import scss from 'rollup-plugin-scss'
import del from 'rollup-plugin-delete'
import { terser } from 'rollup-plugin-terser'
const globals = {
react: 'React',
}
const external = Object.keys(globals)
const extensions = ['.js', '.ts', '.tsx']
const isProd = process.env.NODE_ENV === 'production'
const output = [
{
file: './dist/index.js',
format: 'esm',
globals,
},
]
if (isProd) {
output.push({
file: './dist/index.cjs.js',
format: 'cjs',
name: 'Lightgrid',
globals,
})
}
const plugins = [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
}),
commonjs(),
nodeResolve({
extensions,
}),
typescript(),
scss({ output: './dist/style.css' }),
isProd &&
terser({
module: true,
output: {
comments: false,
},
}),
]
if (isProd) {
plugins.unshift(del({ targets: 'dist/*' }))
}
export default {
input: './src/index.ts',
output,
external,
plugins,
}
{
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment