Skip to content

Instantly share code, notes, and snippets.

@otakustay
Created May 20, 2019 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otakustay/4b6bc0ccb28127bb68a386928c05aaac to your computer and use it in GitHub Desktop.
Save otakustay/4b6bc0ccb28127bb68a386928c05aaac to your computer and use it in GitHub Desktop.
svg icon rollup
const {rollup} = require('rollup');
const babel = require('rollup-plugin-babel');
const svgToReact = require('rollup-plugin-svg-to-jsx');
const autoExternal = require('rollup-plugin-auto-external');
const resolve = require('rollup-plugin-node-resolve');
const css = require('rollup-plugin-postcss');
const babelConfig = {
presets: [
[
'@babel/preset-env',
{
modules: false
}
],
'@babel/preset-react'
],
plugins: [
'@babel/plugin-proposal-export-default-from',
'babel-plugin-react-require'
],
exclude: 'node_modules/**',
extensions: ['.js', '.svg'],
};
const main = async () => {
const plugins= [
resolve(),
css(),
svgToReact(),
babel(babelConfig),
autoExternal({dependencies: false}),
];
const inputOptions = {
context: __dirname,
input: 'lib/svg.js',
plugins: plugins,
};
const bundle = await rollup(inputOptions);
bundle.write({format: 'cjs', file: 'cjs/index.js', sourcemap: true});
bundle.write({format: 'es', file: 'es/index.js', sourcemap: true});
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment