rollup babel无法将let转成var

pychen
  • 7

rollup.config.js

import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
export default {
  input: 'src/main.js',
 output: {
    file: './build/main.js',
 format: 'cjs'
 },
 plugins: [
    resolve(),
 babel({ babelHelpers: 'bundled' })
  ]
};

.babelrc

{
  "presets": [
    [
      "@babel/env"
 ]
  ]
}

源文件main.js

const a = 1;
let b = 2;
const c = () => {console.log("3")};
const d = new Set([1,2,3]);
const e = [1,2,3].includes(1);
export {
  a,b,c,d,e
}

构建出来的文件

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const a = 1;
let b = 2;
const c = () => {
  console.log("3");
};
const d = new Set([1, 2, 3]);
const e = [1, 2, 3].includes(1);
exports.a = a;
exports.b = b;
exports.c = c;
exports.d = d;
exports.e = e;

不知道为什么构建出来来的文件没有转成var,哪位大佬能帮忙解答下

回复
阅读 476
1 个回答

配置package.json的browserslist

宣传栏