使用 Rollup 时,如何让它同时@babel/preset-env
与 和一起使用@babel/polyfill
?提到要添加的文档,useBuiltIns: 'usage'
但是当我这样做时,我require is not defined
在控制台中遇到错误。以下是我到目前为止所拥有的;有更推荐的设置吗?
rollup.config.js:
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
const dist = './dist/';
const name = 'focusoverlay';
export default {
input: './src/index.js',
output: [
{
file: `${dist}${name}.cjs.js`,
format: 'cjs'
},
{
file: `${dist}${name}.esm.js`,
format: 'esm'
},
{
name: 'FocusOverlay',
file: `${dist}${name}.js`,
format: 'umd'
}
],
plugins: [
resolve(),
babel({ exclude: 'node_modules/**' }),
terser()
]
};
.babelrc:
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"modules": false,
"targets": {
"browsers": "> 0.25%, not op_mini all, not dead, IE 10-11",
"node": 6
}
}
]
]
}