Created
May 20, 2019 03:27
-
-
Save otakustay/4b6bc0ccb28127bb68a386928c05aaac to your computer and use it in GitHub Desktop.
svg icon rollup
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
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