Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use rollup and babel for build instead of microbundle (#477)
- Loading branch information
Showing
3 changed files
with
713 additions
and
1,412 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import commonjs from 'rollup-plugin-commonjs'; | ||
import babel from 'rollup-plugin-babel'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import {uglify} from 'rollup-plugin-uglify'; | ||
import pkg from './package.json'; | ||
|
||
const external = (id) => !id.startsWith('.') && !id.startsWith('/'); | ||
|
||
const babelConfig = ( | ||
{useESModules, targets} = { | ||
useESModules: true, | ||
targets: {browsers: 'last 2 versions'}, | ||
}, | ||
) => ({ | ||
comments: false, | ||
runtimeHelpers: true, | ||
presets: [ | ||
'@babel/preset-react', | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets, | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
'@babel/plugin-proposal-class-properties', | ||
['@babel/transform-runtime', {useESModules, regenerator: false}], | ||
['babel-plugin-transform-async-to-promises', {inlineHelpers: true}], | ||
], | ||
exclude: 'node_modules/**', | ||
}); | ||
|
||
const umdConfig = ({minify} = {}) => ({ | ||
input: pkg.source, | ||
external: ['react', 'react-dom', 'prop-types'], | ||
output: { | ||
name: 'SortableHOC', | ||
file: minify ? pkg.browser.replace('.js', '.min.js') : pkg.browser, | ||
format: 'umd', | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'prop-types': 'PropTypes', | ||
}, | ||
}, | ||
plugins: [ | ||
resolve(), | ||
babel( | ||
babelConfig({ | ||
targets: {browsers: ['last 2 versions', 'safari >= 7']}, | ||
}), | ||
), | ||
commonjs(), | ||
minify && uglify(), | ||
filesize(), | ||
], | ||
}); | ||
|
||
const rollupConfig = [ | ||
// Browser-friendly UMD builds | ||
umdConfig(), | ||
umdConfig({minify: true}), | ||
|
||
// CommonJS | ||
{ | ||
input: pkg.source, | ||
external, | ||
output: [{file: pkg.main, format: 'cjs'}], | ||
plugins: [resolve(), babel(babelConfig({useESModules: false})), filesize()], | ||
}, | ||
|
||
// ES module | ||
{ | ||
input: pkg.source, | ||
external, | ||
output: [{file: pkg.module, format: 'esm'}], | ||
plugins: [resolve(), babel(babelConfig()), filesize()], | ||
}, | ||
]; | ||
|
||
export default rollupConfig; |
Oops, something went wrong.