Last active
June 28, 2023 19:58
-
-
Save ShanonJackson/deb65ebf5b2094b3eac6141b9c25a0e3 to your computer and use it in GitHub Desktop.
rollup config
This file contains 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
import css from "rollup-plugin-css-porter"; | |
import pkg from "../../package.json"; | |
import resolve from "rollup-plugin-node-resolve"; | |
import babel from "rollup-plugin-babel"; | |
import path from "path"; | |
import commonjs from "rollup-plugin-commonjs"; | |
import { terser } from "rollup-plugin-terser"; | |
process.env.BABEL_ENV = "production"; | |
process.env.NODE_ENV = "production"; | |
const extensions = [".js", ".jsx", ".ts", ".tsx", ".css"]; | |
const makeExternalPredicate = externalArr => { | |
if (externalArr.length === 0) return () => false; | |
return id => new RegExp(`^(${externalArr.join('|')})($|/)`).test(id); | |
}; | |
export default { | |
input: ['src/export/index.ts'], | |
preserveModules: false, | |
output: [{ | |
dir: 'dist', | |
sourcemapPathTransform: relativePath => { | |
return path.relative('src', relativePath) | |
}, | |
format: 'cjs', | |
sourcemap: false | |
}], | |
external: makeExternalPredicate(Object.keys(pkg.peerDependencies || {}).concat(Object.keys(pkg.dependencies || {}))), | |
plugins: [ | |
commonjs({ | |
include: "node_modules/**", | |
namedExports: { | |
"node_modules/react-with-gesture/dist/react-with-gesture": ["useGesture"], | |
"node_modules/react-spring/web.js": ["animated", "useSpring", "useTransition", "config", "interpolate"], | |
"node_modules/react-spring/renderprops.cjs": ["Spring", "animated"], | |
"node_modules/linaria": ["cx", "css"], | |
"node_modules/linaria/react.js": ["styled"], | |
"node_modules/react-dom/index.js": [ | |
"findDOMNode", | |
"createPortal", | |
], | |
"node_modules/react/index.js": [ | |
"Component", | |
"PureComponent", | |
"Fragment", | |
"cloneElement", | |
"forwardRef", | |
"createElement", | |
"createFactory", | |
"Children", | |
"createContext", | |
"createRef", | |
"isValidElement", | |
"lazy", | |
"memo", | |
"Suspense", | |
"Profiler", | |
"StrictMode", | |
"useContext", | |
"useDebugValue", | |
"useImperativeHandle", | |
"useMemo", | |
"useReducer", | |
"useRef", | |
"useState", | |
"useLayoutEffect", | |
"useEffect", | |
"useCallback", | |
"version" | |
], | |
}, | |
}), | |
resolve({ extensions }), | |
css({ | |
dest: "./dist/styles.css", | |
minified: true, | |
}), | |
babel({ | |
babelHelpers: "runtime", | |
extensions, | |
include: ["src/**/*"], | |
exclude: "node_modules/**", | |
babelrc: true | |
}), | |
terser({ | |
compress: { | |
passes: 10 | |
} | |
}) | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a really nice suggestion you posted on stackoverflow
Was wondering if you have an updated setup in 2021?
Most of the Rollup plugins are under the @rollup/plugin... Name now.